(
public descriptor: SFCDescriptor,
public options: Partial<SFCScriptCompileOptions>,
)
| 81 | fs?: NonNullable<SFCScriptCompileOptions['fs']> |
| 82 | |
| 83 | constructor( |
| 84 | public descriptor: SFCDescriptor, |
| 85 | public options: Partial<SFCScriptCompileOptions>, |
| 86 | ) { |
| 87 | const { script, scriptSetup } = descriptor |
| 88 | const scriptLang = script && script.lang |
| 89 | const scriptSetupLang = scriptSetup && scriptSetup.lang |
| 90 | |
| 91 | this.isJS = isJS(scriptLang, scriptSetupLang) |
| 92 | this.isTS = isTS(scriptLang, scriptSetupLang) |
| 93 | |
| 94 | const customElement = options.customElement |
| 95 | const filename = this.descriptor.filename |
| 96 | if (customElement) { |
| 97 | this.isCE = |
| 98 | typeof customElement === 'boolean' |
| 99 | ? customElement |
| 100 | : customElement(filename) |
| 101 | } |
| 102 | // resolve parser plugins |
| 103 | const plugins: ParserPlugin[] = resolveParserPlugins( |
| 104 | (scriptLang || scriptSetupLang)!, |
| 105 | options.babelParserPlugins, |
| 106 | ) |
| 107 | |
| 108 | function parse(input: string, offset: number): Program { |
| 109 | try { |
| 110 | return babelParse(input, { |
| 111 | plugins, |
| 112 | sourceType: 'module', |
| 113 | }).program |
| 114 | } catch (e: any) { |
| 115 | e.message = `[vue/compiler-sfc] ${e.message}\n\n${ |
| 116 | descriptor.filename |
| 117 | }\n${generateCodeFrame( |
| 118 | descriptor.source, |
| 119 | e.pos + offset, |
| 120 | e.pos + offset + 1, |
| 121 | )}` |
| 122 | throw e |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | this.scriptAst = |
| 127 | descriptor.script && |
| 128 | parse(descriptor.script.content, descriptor.script.loc.start.offset) |
| 129 | |
| 130 | this.scriptSetupAst = |
| 131 | descriptor.scriptSetup && |
| 132 | parse(descriptor.scriptSetup!.content, this.startOffset!) |
| 133 | } |
| 134 | |
| 135 | getString(node: Node, scriptSetup = true): string { |
| 136 | const block = scriptSetup |
nothing calls this directly
no test coverage detected