diff --git a/.eslintignore b/.eslintignore index b77b6607..537f1533 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,7 @@ /.nyc_output /.temp /coverage -/node_modules +node_modules /src/external /src/html/util /test/fixtures diff --git a/.gitignore b/.gitignore index 6ea559ee..8bf60fc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ /.nyc_output /.temp /coverage -/node_modules +node_modules /test/temp /index.* /npm-debug.log /test.js /test/fixtures/espree-v8/node_modules +/test/fixtures/integrations/**/_actual.json diff --git a/scripts/update-fixtures-ast.js b/scripts/update-fixtures-ast.js index 241c2c36..6e6cc54c 100644 --- a/scripts/update-fixtures-ast.js +++ b/scripts/update-fixtures-ast.js @@ -27,6 +27,7 @@ const PARSER_OPTIONS = { loc: true, range: true, tokens: true, + eslintScopeManager: true, } /** diff --git a/src/common/parser-options.ts b/src/common/parser-options.ts index 3000bd76..fd459310 100644 --- a/src/common/parser-options.ts +++ b/src/common/parser-options.ts @@ -35,6 +35,9 @@ export interface ParserOptions { range?: boolean tokens?: boolean + // From ESLint + eslintScopeManager?: boolean + // others // [key: string]: any } diff --git a/src/index.ts b/src/index.ts index afff45e1..eff1ef93 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,8 @@ import { isTemplateElement, } from "./common/ast-utils" import { parseStyleElements } from "./style" +import { analyzeScope } from "./script/scope-analyzer" +import { analyzeScriptSetupScope } from "./script-setup/scope-analyzer" const STARTS_WITH_LT = /^\s* { - const ext = ( - path - .extname(options.filePath || "unknown.js") - .toLowerCase() || "" - ) - // remove dot - .slice(1) - if (/^[jt]sx$/u.test(ext)) { - return [ext, ext.slice(0, -1)] - } - - return ext - }), - }) + result = parseAsScript(code, options) document = null locationCalculator = null } else { - const optionsForTemplate = { - ...options, - ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, - } - const skipParsingScript = options.parser === false - const tokenizer = new HTMLTokenizer(code, optionsForTemplate) - const rootAST = new HTMLParser(tokenizer, optionsForTemplate).parse() - - locationCalculator = new LocationCalculatorForHtml( - tokenizer.gaps, - tokenizer.lineTerminators, - ) - const scripts = rootAST.children.filter(isScriptElement) - const template = rootAST.children.find(isTemplateElement) - const templateLang = getLang(template) || "html" - const concreteInfo: AST.HasConcreteInfo = { - tokens: rootAST.tokens, - comments: rootAST.comments, - errors: rootAST.errors, - } - const templateBody = - template != null && templateLang === "html" - ? Object.assign(template, concreteInfo) - : undefined - - const scriptParser = getScriptParser(options.parser, () => - getParserLangFromSFC(rootAST), - ) - let scriptSetup: VElement | undefined - if (skipParsingScript || !scripts.length) { - result = parseScript("", { - ...options, - ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, - parser: scriptParser, - }) - } else if ( - scripts.length === 2 && - (scriptSetup = scripts.find(isScriptSetupElement)) - ) { - result = parseScriptSetupElements( - scriptSetup, - scripts.find((e) => e !== scriptSetup)!, - code, - new LinesAndColumns(tokenizer.lineTerminators), - { - ...options, - parser: scriptParser, - }, - ) - } else { - result = parseScriptElement( - scripts[0], - code, - new LinesAndColumns(tokenizer.lineTerminators), - { - ...options, - parser: scriptParser, - }, - ) - } - - if (options.vueFeatures?.styleCSSVariableInjection ?? true) { - const styles = rootAST.children.filter(isStyleElement) - parseStyleElements(styles, locationCalculator, { - ...options, - parser: getScriptParser(options.parser, function* () { - yield "