diff --git a/scripts/update-fixtures-ast.js b/scripts/update-fixtures-ast.js index a998c3f..6f6e780 100644 --- a/scripts/update-fixtures-ast.js +++ b/scripts/update-fixtures-ast.js @@ -102,11 +102,11 @@ for (const name of TARGETS) { const servicesPath = path.join(ROOT, `${name}/services.json`) const source = fs.readFileSync(sourcePath, "utf8") const parserOptions = optionsPath ? require(optionsPath) : {} - const options = Object.assign( - { filePath: sourcePath }, - PARSER_OPTIONS, - parserOptions, - ) + const options = { + filePath: sourcePath, + ...PARSER_OPTIONS, + ...parserOptions, + } // console.log("Start:", name) const actual = parser.parseForESLint(source, options) const tokenRanges = getAllTokens(actual.ast).map((t) => diff --git a/scripts/update-fixtures-document-fragment.js b/scripts/update-fixtures-document-fragment.js index a0a0c64..470bc26 100644 --- a/scripts/update-fixtures-document-fragment.js +++ b/scripts/update-fixtures-document-fragment.js @@ -58,11 +58,12 @@ for (const name of TARGETS) { path.join(ROOT, `${name}/parser-options.js`), ].find((fp) => fs.existsSync(fp)) const source = fs.readFileSync(sourcePath, "utf8") - const options = Object.assign( - { filePath: sourcePath }, - PARSER_OPTIONS, - optionsPath ? require(optionsPath) : {}, - ) + const options = { + filePath: sourcePath, + ...PARSER_OPTIONS, + ...(optionsPath ? require(optionsPath) : {}), + } + const result = parser.parseForESLint(source, options) const actual = result.services.getDocumentFragment() diff --git a/src/ast/traverse.ts b/src/ast/traverse.ts index 448f210..13cec66 100644 --- a/src/ast/traverse.ts +++ b/src/ast/traverse.ts @@ -27,6 +27,7 @@ export const KEYS = Evk.unionWith({ VSlotScopeExpression: ["params"], VStartTag: ["attributes"], VText: [], + VGenericExpression: ["expression"], }) /** @@ -82,7 +83,7 @@ function traverse(node: Node, parent: Node | null, visitor: Visitor): void { visitor.enterNode(node, parent) const keys = - (visitor.visitorKeys || KEYS)[node.type] || getFallbackKeys(node) + (visitor.visitorKeys ?? KEYS)[node.type] ?? getFallbackKeys(node) for (i = 0; i < keys.length; ++i) { const child = (node as any)[keys[i]] diff --git a/src/common/ast-utils.ts b/src/common/ast-utils.ts index 689b373..ae541bc 100644 --- a/src/common/ast-utils.ts +++ b/src/common/ast-utils.ts @@ -78,8 +78,8 @@ export function isLang( * @returns The `lang` attribute value. */ export function getLang(element: VElement | undefined): string | null { - const langAttr = element && element.startTag.attributes.find(isLang) - const lang = langAttr && langAttr.value && langAttr.value.value + const langAttr = element?.startTag.attributes.find(isLang) + const lang = langAttr?.value?.value return lang || null } /** diff --git a/src/common/eslint-scope.ts b/src/common/eslint-scope.ts index a0e9681..d5a0db2 100644 --- a/src/common/eslint-scope.ts +++ b/src/common/eslint-scope.ts @@ -12,7 +12,7 @@ let escopeCache: ESLintScope | null = null * Load the newest `eslint-scope` from the loaded ESLint or dependency. */ export function getEslintScope(): ESLintScope { - return escopeCache || (escopeCache = getNewest()) + return escopeCache ?? (escopeCache = getNewest()) } /** diff --git a/src/common/espree.ts b/src/common/espree.ts index f9c1efc..8622ff3 100644 --- a/src/common/espree.ts +++ b/src/common/espree.ts @@ -16,7 +16,7 @@ let espreeCache: Espree | null = null * Gets the espree that the given ecmaVersion can parse. */ export function getEspree(): Espree { - return espreeCache || (espreeCache = getNewestEspree()) + return espreeCache ?? (espreeCache = getNewestEspree()) } export function getEcmaVersionIfUseEspree( diff --git a/src/common/fix-locations.ts b/src/common/fix-locations.ts index 8772ba8..6bdbdb0 100644 --- a/src/common/fix-locations.ts +++ b/src/common/fix-locations.ts @@ -24,10 +24,10 @@ export function fixLocations( ): void { fixNodeLocations(result.ast, result.visitorKeys, locationCalculator) - for (const token of result.ast.tokens || []) { + for (const token of result.ast.tokens ?? []) { fixLocation(token, locationCalculator) } - for (const comment of result.ast.comments || []) { + for (const comment of result.ast.comments ?? []) { fixLocation(comment, locationCalculator) } } diff --git a/src/common/location-calculator.ts b/src/common/location-calculator.ts index 6f45cec..8c8cf34 100644 --- a/src/common/location-calculator.ts +++ b/src/common/location-calculator.ts @@ -62,7 +62,7 @@ export class LocationCalculatorForHtml super(ltOffsets) this.gapOffsets = gapOffsets this.ltOffsets = ltOffsets - this.baseOffset = baseOffset || 0 + this.baseOffset = baseOffset ?? 0 this.baseIndexOfGap = this.baseOffset === 0 ? 0 diff --git a/src/external/token-store/index.ts b/src/external/token-store/index.ts index 1a6af0b..a0bdabb 100644 --- a/src/external/token-store/index.ts +++ b/src/external/token-store/index.ts @@ -334,7 +334,7 @@ export default class TokenStore { ) .getOneToken() - if (token && token.range[0] === offset) { + if (token?.range[0] === offset) { return token } return null diff --git a/src/html/intermediate-tokenizer.ts b/src/html/intermediate-tokenizer.ts index 50b31ca..62d4ca9 100644 --- a/src/html/intermediate-tokenizer.ts +++ b/src/html/intermediate-tokenizer.ts @@ -222,7 +222,7 @@ export class IntermediateTokenizer { private processComment(token: Token): IntermediateToken | null { this.comments.push(token) - if (this.currentToken != null && this.currentToken.type === "Text") { + if (this.currentToken?.type === "Text") { return this.commit() } return null diff --git a/src/html/parser.ts b/src/html/parser.ts index 367eecc..ed155e9 100644 --- a/src/html/parser.ts +++ b/src/html/parser.ts @@ -421,7 +421,7 @@ export class Parser { if (name === "template") { const xmlns = token.attributes.find((a) => a.key.name === "xmlns") - const value = xmlns && xmlns.value && xmlns.value.value + const value = xmlns?.value?.value if (value === NS.HTML || value === NS.MathML || value === NS.SVG) { return value @@ -477,7 +477,7 @@ export class Parser { node.key.name = adjustAttributeName(node.key.name, namespace) const key = this.getTagName(node.key) - const value = node.value && node.value.value + const value = node.value?.value if (key === "xmlns" && value !== namespace) { this.reportParseError(node, "x-invalid-namespace") @@ -616,8 +616,7 @@ export class Parser { for (const attribute of element.startTag.attributes) { if (attribute.directive) { if ( - attribute.key.argument != null && - attribute.key.argument.type === "VExpressionContainer" + attribute.key.argument?.type === "VExpressionContainer" ) { resolveReferences(attribute.key.argument) } diff --git a/src/html/tokenizer.ts b/src/html/tokenizer.ts index 220eb5e..6285cdf 100644 --- a/src/html/tokenizer.ts +++ b/src/html/tokenizer.ts @@ -980,8 +980,7 @@ export class Tokenizer { function maybeValidCustomBlock(this: Tokenizer, nextCp: number) { return ( this.currentToken && - this.lastTagOpenToken && - this.lastTagOpenToken.value.startsWith( + this.lastTagOpenToken?.value.startsWith( this.currentToken.value + String.fromCodePoint(nextCp), ) ) diff --git a/src/index.ts b/src/index.ts index 3b45a18..3b0c462 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,15 +49,13 @@ export function parseForESLint( code: string, parserOptions: any, ): AST.ESLintExtendedProgram { - const options: ParserOptions = Object.assign( - { - comment: true, - loc: true, - range: true, - tokens: true, - }, - parserOptions || {}, - ) + const options: ParserOptions = { + comment: true, + loc: true, + range: true, + tokens: true, + ...(parserOptions ?? {}), + } let result: AST.ESLintExtendedProgram let document: AST.VDocumentFragment | null @@ -70,12 +68,12 @@ export function parseForESLint( ;({ result, document, locationCalculator } = parseAsSFC(code, options)) } - result.services = Object.assign( - result.services || {}, - services.define(code, result.ast, document, locationCalculator, { + result.services = { + ...(result.services || {}), + ...services.define(code, result.ast, document, locationCalculator, { parserOptions: options, }), - ) + } return result } @@ -96,7 +94,7 @@ export { AST } function parseAsSFC(code: string, options: ParserOptions) { const optionsForTemplate = { ...options, - ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, + ecmaVersion: options.ecmaVersion ?? DEFAULT_ECMA_VERSION, } const skipParsingScript = options.parser === false const tokenizer = new HTMLTokenizer(code, optionsForTemplate) @@ -128,7 +126,7 @@ function parseAsSFC(code: string, options: ParserOptions) { if (skipParsingScript || !scripts.length) { result = parseScript("", { ...options, - ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, + ecmaVersion: options.ecmaVersion ?? DEFAULT_ECMA_VERSION, parser: scriptParser, }) } else if ( @@ -195,7 +193,7 @@ function parseAsSFC(code: string, options: ParserOptions) { function parseAsScript(code: string, options: ParserOptions) { return parseScript(code, { ...options, - ecmaVersion: options.ecmaVersion || DEFAULT_ECMA_VERSION, + ecmaVersion: options.ecmaVersion ?? DEFAULT_ECMA_VERSION, parser: getScriptParser(options.parser, () => { const ext = ( path.extname(options.filePath || "unknown.js").toLowerCase() || diff --git a/src/parser-services.ts b/src/parser-services.ts index 5916c1a..3b830c4 100644 --- a/src/parser-services.ts +++ b/src/parser-services.ts @@ -341,7 +341,7 @@ export function define( ) // Register handlers into the intermediate event emitter. for (const selector of Object.keys( - visitor || {}, + visitor ?? {}, )) { emitter.on(selector, visitor![selector]) } diff --git a/src/script-setup/index.ts b/src/script-setup/index.ts index 52c15ee..671a2bc 100644 --- a/src/script-setup/index.ts +++ b/src/script-setup/index.ts @@ -216,7 +216,7 @@ export function parseScriptSetupElements( ): ESLintExtendedProgram { const parserOptions: ParserOptions = { ...originalParserOptions, - ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION, + ecmaVersion: originalParserOptions.ecmaVersion ?? DEFAULT_ECMA_VERSION, } const scriptSetupModuleCodeBlocks = getScriptSetupModuleCodeBlocks( scriptSetupElement, @@ -323,7 +323,7 @@ export function parseScriptSetupElements( const textNode = node.children[0] return Math.min( start, - textNode != null && textNode.type === "VText" + textNode?.type === "VText" ? textNode.range[0] : node.startTag.range[1], ) @@ -344,7 +344,7 @@ export function parseScriptSetupElements( const textNode = node.children[0] return Math.max( end, - textNode != null && textNode.type === "VText" + textNode?.type === "VText" ? textNode.range[1] : (node.endTag?.range[0] ?? node.range[1]), ) @@ -575,7 +575,7 @@ function getScriptSetupCodeBlocks( (t) => t.range[0] === body.range[0], ) const exportToken = tokens[exportTokenIndex] - if (exportToken && exportToken.value === "export") { + if (exportToken?.value === "export") { // Consume code up to the start position of `export`. // The code may contain legacy decorators. append(statementCodeBlocks, usedOffset, exportToken.range[0]) @@ -958,7 +958,7 @@ function remapLocationAndTokens( { codeBlocks }: ScriptSetupModuleCodeBlocks, locationCalculator: LocationCalculator, ) { - const tokens = result.ast.tokens || [] + const tokens = result.ast.tokens ?? [] const endMap = new Map() const buffer: number[] = [] diff --git a/src/script-setup/scope-analyzer.ts b/src/script-setup/scope-analyzer.ts index a7e3dee..0016b99 100644 --- a/src/script-setup/scope-analyzer.ts +++ b/src/script-setup/scope-analyzer.ts @@ -131,7 +131,7 @@ function extractVariables(scopeManager: escopeTypes.ScopeManager) { const moduleScope = globalScope.childScopes.find( (scope) => scope.type === "module", ) - for (const variable of (moduleScope && moduleScope.variables) || []) { + for (const variable of moduleScope?.variables ?? []) { scriptVariables.set(variable.name, variable) } return scriptVariables diff --git a/src/script/index.ts b/src/script/index.ts index 5677e0f..261e575 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -375,8 +375,8 @@ function parseExpressionBody( parserOptions, ) const { ast } = result - const tokens = ast.tokens || [] - const comments = ast.comments || [] + const tokens = ast.tokens ?? [] + const comments = ast.comments ?? [] const references = analyzeExternalReferences(result, parserOptions) const statement = ast.body[0] as ESLintExpressionStatement const callExpression = statement.expression as ESLintCallExpression @@ -385,7 +385,7 @@ function parseExpressionBody( if (!allowEmpty && !expression) { return throwEmptyError(locationCalculator, "an expression") } - if (expression && expression.type === "SpreadElement") { + if (expression?.type === "SpreadElement") { return throwUnexpectedTokenError("...", expression) } if (callExpression.arguments[1]) { @@ -610,14 +610,14 @@ export function parseScriptElement( ): ESLintExtendedProgram { const parserOptions: ParserOptions = { ...originalParserOptions, - ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION, + ecmaVersion: originalParserOptions.ecmaVersion ?? DEFAULT_ECMA_VERSION, } let generic: GenericProcessInfo | null = null let code: string let offset: number const textNode = node.children[0] - if (textNode != null && textNode.type === "VText") { + if (textNode?.type === "VText") { const [scriptStartOffset, scriptEndOffset] = textNode.range code = sfcCode.slice(scriptStartOffset, scriptEndOffset) offset = scriptStartOffset @@ -738,8 +738,8 @@ export function parseExpression( parent: null as any, expression: retB.expression, filters: [], - range: retB.expression.range.slice(0) as [number, number], - loc: Object.assign({}, retB.expression.loc), + range: [...retB.expression.range] as const, + loc: { ...retB.expression.loc }, } ret.expression.expression.parent = ret.expression @@ -831,8 +831,8 @@ export function parseVForExpression( parserOptions, ) const { ast } = result - const tokens = ast.tokens || [] - const comments = ast.comments || [] + const tokens = ast.tokens ?? [] + const comments = ast.comments ?? [] const scope = analyzeVariablesAndExternalReferences( result, "v-for", @@ -1013,8 +1013,8 @@ function parseVForAliasesForEcmaVersion5( parserOptions, ) const { ast } = result - const tokens = ast.tokens || [] - const comments = ast.comments || [] + const tokens = ast.tokens ?? [] + const comments = ast.comments ?? [] const variables = analyzeExternalReferences(result, parserOptions).map( transformVariable, ) @@ -1064,8 +1064,8 @@ function parseVForIteratorForEcmaVersion5( parserOptions, ) const { ast } = result - const tokens = ast.tokens || [] - const comments = ast.comments || [] + const tokens = ast.tokens ?? [] + const comments = ast.comments ?? [] const references = analyzeExternalReferences(result, parserOptions) const statement = ast.body[0] as ESLintExpressionStatement @@ -1075,7 +1075,7 @@ function parseVForIteratorForEcmaVersion5( if (!expression) { return throwEmptyError(locationCalculator, "an expression") } - if (expression && expression.type === "SpreadElement") { + if (expression?.type === "SpreadElement") { return throwUnexpectedTokenError("...", expression) } const right = expression @@ -1162,8 +1162,8 @@ function parseVOnExpressionBody( parent: DUMMY_PARENT, body, } - const tokens = ast.tokens || [] - const comments = ast.comments || [] + const tokens = ast.tokens ?? [] + const comments = ast.comments ?? [] // Modify parent. for (const b of body) { @@ -1223,8 +1223,8 @@ export function parseSlotScopeExpression( } } - const tokens = ast.tokens || [] - const comments = ast.comments || [] + const tokens = ast.tokens ?? [] + const comments = ast.comments ?? [] const scope = analyzeVariablesAndExternalReferences( result, "scope", @@ -1322,8 +1322,8 @@ export function parseGenericExpression( } } - const tokens = ast.tokens || [] - const comments = ast.comments || [] + const tokens = ast.tokens ?? [] + const comments = ast.comments ?? [] const scope = analyzeVariablesAndExternalReferences( result, "generic", diff --git a/src/script/scope-analyzer.ts b/src/script/scope-analyzer.ts index 0f42cab..309bc68 100644 --- a/src/script/scope-analyzer.ts +++ b/src/script/scope-analyzer.ts @@ -102,10 +102,10 @@ export function analyzeScope( parserOptions: ParserOptions, ): escopeTypes.ScopeManager { const ecmaVersion = - getEcmaVersionIfUseEspree(parserOptions) || + getEcmaVersionIfUseEspree(parserOptions) ?? ANALYZE_SCOPE_DEFAULT_ECMA_VERSION - const ecmaFeatures = parserOptions.ecmaFeatures || {} - const sourceType = parserOptions.sourceType || "script" + const ecmaFeatures = parserOptions.ecmaFeatures ?? {} + const sourceType = parserOptions.sourceType ?? "script" const result = getEslintScope().analyze(ast, { ignoreEval: true, nodejsScope: false, diff --git a/src/sfc/custom-block/index.ts b/src/sfc/custom-block/index.ts index 734824e..6ccfd4c 100644 --- a/src/sfc/custom-block/index.ts +++ b/src/sfc/custom-block/index.ts @@ -87,7 +87,7 @@ export function parseCustomBlockElement( ): ESLintExtendedProgram & { error?: ParseError | Error } { const text = node.children[0] const { code, range, loc } = - text != null && text.type === "VText" + text?.type === "VText" ? { code: text.value, range: text.range, @@ -263,7 +263,7 @@ export function createCustomBlockSharedContext({ { ...parserOptions, ...options }, ) }, - ...(parsedResult.services || {}), + ...(parsedResult.services ?? {}), ...(parsedResult.error ? { parseError: parsedResult.error } : {}), @@ -295,10 +295,10 @@ export function createCustomBlockSharedContext({ } const ecmaVersion = - getEcmaVersionIfUseEspree(parserOptions) || + getEcmaVersionIfUseEspree(parserOptions) ?? ANALYZE_SCOPE_DEFAULT_ECMA_VERSION - const ecmaFeatures = parserOptions.ecmaFeatures || {} - const sourceType = parserOptions.sourceType || "script" + const ecmaFeatures = parserOptions.ecmaFeatures ?? {} + const sourceType = parserOptions.sourceType ?? "script" return getEslintScope().analyze(parsedResult.ast, { ignoreEval: true, nodejsScope: false, @@ -341,7 +341,7 @@ function getScope(scopeManager: ScopeManager, currentNode: Node) { for ( let node: Node | null = currentNode; node; - node = node.parent || null + node = node.parent ?? null ) { const scope = scopeManager.acquire(node as any, inner) diff --git a/src/style/index.ts b/src/style/index.ts index 2b3be86..bcc01dc 100644 --- a/src/style/index.ts +++ b/src/style/index.ts @@ -36,7 +36,7 @@ class CSSTokenScanner { this.tokenizer = new CSSTokenizer(text, 0, options) } public nextToken(): CSSToken | null { - return this.reconsuming.shift() || this.tokenizer.nextToken() + return this.reconsuming.shift() ?? this.tokenizer.nextToken() } public reconsume(...tokens: CSSToken[]) { this.reconsuming.push(...tokens) @@ -57,7 +57,7 @@ export function parseStyleElements( ): void { const parserOptions: ParserOptions = { ...originalParserOptions, - ecmaVersion: originalParserOptions.ecmaVersion || DEFAULT_ECMA_VERSION, + ecmaVersion: originalParserOptions.ecmaVersion ?? DEFAULT_ECMA_VERSION, } for (const style of elements) { @@ -372,7 +372,7 @@ function parseVBindArg(tokenizer: CSSTokenScanner): { comments, } } - const startToken = tokensBuffer[0] || token + const startToken = tokensBuffer[0] ?? token return { exprRange: [startToken.range[0], token.range[0]], quote: null, diff --git a/src/template/index.ts b/src/template/index.ts index 1440e05..80c3f76 100644 --- a/src/template/index.ts +++ b/src/template/index.ts @@ -159,7 +159,7 @@ function parseDirectiveKeyStatically( if (directiveKey.name == null) { directiveKey.name = modifiers.shift()! } else if (directiveKey.argument == null && modifiers[0].name !== "") { - directiveKey.argument = modifiers.shift() || null + directiveKey.argument = modifiers.shift() ?? null } directiveKey.modifiers = modifiers.filter(isNotEmptyModifier) @@ -553,7 +553,7 @@ function resolveReference(referene: Reference, element: VElement): void { let node: VNode | null = element // Find the variable of this reference. - while (node != null && node.type === "VElement") { + while (node?.type === "VElement") { for (const variable of node.variables) { if (variable.id.name === referene.id.name) { referene.variable = variable @@ -592,7 +592,7 @@ export function convertToDirective( debug( '[template] convert to directive: %s="%s" %j', node.key.name, - node.value && node.value.value, + node.value?.value, node.range, ) @@ -607,11 +607,7 @@ export function convertToDirective( ) const { argument } = directive.key - if ( - argument && - argument.type === "VIdentifier" && - argument.name.startsWith("[") - ) { + if (argument?.type === "VIdentifier" && argument.name.startsWith("[")) { const nextChar = code[argument.range[1]] if (nextChar == null || invalidDynamicArgumentNextChar.test(nextChar)) { const char = @@ -778,7 +774,7 @@ export function processMustache( { allowEmpty: true, allowFilters: true }, ) - node.expression = ret.expression || null + node.expression = ret.expression ?? null node.references = ret.references if (ret.expression != null) { ret.expression.parent = node diff --git a/test/ast.js b/test/ast.js index c984b82..c033c80 100644 --- a/test/ast.js +++ b/test/ast.js @@ -77,8 +77,8 @@ function getTree(source, parserOptions) { }, languageOptions: { parser: parser, - ecmaVersion: parserOptions.ecmaVersion || "latest", - sourceType: parserOptions.sourceType || "module", + ecmaVersion: parserOptions.ecmaVersion ?? "latest", + sourceType: parserOptions.sourceType ?? "module", parserOptions: parserOptions, }, rules: { "test/maketree": "error" }, @@ -148,8 +148,8 @@ function validateParent(source, parserOptions) { }, languageOptions: { parser, - ecmaVersion: parserOptions.ecmaVersion || "latest", - sourceType: parserOptions.sourceType || "module", + ecmaVersion: parserOptions.ecmaVersion ?? "latest", + sourceType: parserOptions.sourceType ?? "module", parserOptions: parserOptions, }, rules: { "test/validateparent": "error" }, @@ -191,11 +191,11 @@ describe("Template AST", () => { ), ) } - const options = Object.assign( - { filePath: sourcePath }, - PARSER_OPTIONS, - parserOptions, - ) + const options = { + filePath: sourcePath, + ...PARSER_OPTIONS, + ...parserOptions, + } if ( Object.entries(requirements).some(([pkgName, pkgVersion]) => { @@ -253,7 +253,7 @@ describe("Template AST", () => { }) it("should have correct location.", () => { - const lines = source.match(/[^\r\n]*(?:\r?\n|$)/gu) || [] + const lines = source.match(/[^\r\n]*(?:\r?\n|$)/gu) ?? [] lines.push(String.fromCodePoint(0)) for (const token of getAllTokens(actual.ast)) { const line0 = token.loc.start.line - 1 diff --git a/test/document-fragment.js b/test/document-fragment.js index b824ca7..9204ce7 100644 --- a/test/document-fragment.js +++ b/test/document-fragment.js @@ -61,11 +61,11 @@ describe("services.getDocumentFragment", () => { ].find((fp) => fs.existsSync(fp)) const source = fs.readFileSync(sourcePath, "utf8") const parserOptions = optionsPath ? require(optionsPath) : {} - const options = Object.assign( - { filePath: sourcePath }, - PARSER_OPTIONS, - parserOptions, - ) + const options = { + filePath: sourcePath, + ...PARSER_OPTIONS, + ...parserOptions, + } const result = parser.parseForESLint(source, options) const actual = result.services.getDocumentFragment() diff --git a/test/test-utils.js b/test/test-utils.js index 7ffa8e1..8ea0b76 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -68,7 +68,7 @@ function scopeToJSON(scopeManager) { reference.resolved.defs[0] && reference.resolved.defs[0].name, ), - init: reference.init || null, + init: reference.init ?? null, vueUsedInTemplate: reference.vueUsedInTemplate ? reference.vueUsedInTemplate : undefined, @@ -105,9 +105,9 @@ function scopeToJSON(scopeManager) { * Analyze scope */ function analyze(ast, parserOptions) { - const ecmaVersion = parserOptions.ecmaVersion || 2022 - const ecmaFeatures = parserOptions.ecmaFeatures || {} - const sourceType = parserOptions.sourceType || "script" + const ecmaVersion = parserOptions.ecmaVersion ?? 2022 + const ecmaFeatures = parserOptions.ecmaFeatures ?? {} + const sourceType = parserOptions.sourceType ?? "script" const result = escope.analyze(ast, { ignoreEval: true, nodejsScope: false, diff --git a/test/tokens.js b/test/tokens.js index 09cc4a2..51a68c2 100644 --- a/test/tokens.js +++ b/test/tokens.js @@ -52,10 +52,7 @@ describe("services.getTemplateBodyTokenStore", () => { let tokens = null before(() => { - const result = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ) + const result = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }) ast = result.ast tokens = result.services.getTemplateBodyTokenStore() }) diff --git a/test/variables-references.js b/test/variables-references.js index 8a43d0a..4e6a590 100644 --- a/test/variables-references.js +++ b/test/variables-references.js @@ -34,10 +34,7 @@ describe("[references] expression containers", () => { let ast = null before(() => { - ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast }) it("should have references", () => { @@ -62,10 +59,7 @@ describe("[references] expression containers", () => { let ast = null before(() => { - ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast }) it("should have references", () => { @@ -83,10 +77,7 @@ describe("[references] expression containers", () => { let ast = null before(() => { - ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast }) it("should not include $event references.", () => { @@ -110,10 +101,7 @@ describe("[variables] elements", () => { let ast = null before(() => { - ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast }) it("should have references", () => { @@ -138,10 +126,7 @@ describe("[variables] elements", () => { let ast = null before(() => { - ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast }) it("should have references", () => { @@ -169,10 +154,7 @@ describe("[variables] elements", () => { let ast = null before(() => { - ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast }) it("should have variables", () => { @@ -204,10 +186,7 @@ describe("Variables of v-for and references", () => { let mustacheReferences3 = null before(() => { - const ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + const ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast variables = ast.templateBody.children[0].variables vForReferences = ast.templateBody.children[0].startTag.attributes[0].value.references @@ -274,10 +253,7 @@ describe("Variables of template-scope and references", () => { let mustacheReferences3 = null before(() => { - const ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + const ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast variables = ast.templateBody.children[0].variables vBindKeyReferences = ast.templateBody.children[0].startTag.attributes[1].value.references @@ -336,10 +312,7 @@ describe("Variables of v-for and references of dynamic arguments", () => { let vBindKeyReferences = null before(() => { - const ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + const ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast variables = ast.templateBody.children[0].variables vForReferences = ast.templateBody.children[0].startTag.attributes[0].value.references @@ -366,10 +339,7 @@ describe("Variables of v-for and references of v-bind same-name shorthand", () = let vBindReferences = null before(() => { - const ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + const ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast variables = ast.templateBody.children[0].variables vForReferences = ast.templateBody.children[0].startTag.attributes[0].value.references @@ -395,10 +365,7 @@ describe("Variables of v-for and references of v-bind same-name shorthand with k let vBindReferences = null before(() => { - const ast = parse( - code, - Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), - ).ast + const ast = parse(code, { filePath: "test.vue", ...PARSER_OPTIONS }).ast variables = ast.templateBody.children[0].variables vForReferences = ast.templateBody.children[0].startTag.attributes[0].value.references diff --git a/tsconfig.json b/tsconfig.json index e439796..e4cbfcc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,41 +1,41 @@ { - "compileOnSave": true, - "compilerOptions": { - "allowJs": false, - "allowSyntheticDefaultImports": true, - "allowUnreachableCode": false, - "allowUnusedLabels": false, - "alwaysStrict": true, - "baseUrl": ".", - "checkJs": false, - "declaration": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "inlineSources": true, - "lib": ["es2015"], - "module": "commonjs", - "moduleResolution": "node", - "newLine": "LF", - "noEmitOnError": true, - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "outDir": ".temp", - "paths": { - "*": ["typings/*"] - }, - "pretty": true, - "removeComments": true, - "sourceMap": true, - "sourceRoot": "src", - "strict": true, - "strictNullChecks": true, - "target": "es2015", - - "skipLibCheck": true, + "compileOnSave": true, + "compilerOptions": { + "allowJs": false, + "allowSyntheticDefaultImports": true, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "alwaysStrict": true, + "baseUrl": ".", + "checkJs": false, + "declaration": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "inlineSources": true, + "lib": ["es2015"], + "module": "commonjs", + "moduleResolution": "node", + "newLine": "LF", + "noEmitOnError": true, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "outDir": ".temp", + "paths": { + "*": ["typings/*"] }, - "include": ["src/**/*.ts"] + "pretty": true, + "removeComments": true, + "sourceMap": true, + "sourceRoot": "src", + "strict": true, + "strictNullChecks": true, + "target": "ES2024", + + "skipLibCheck": true + }, + "include": ["src/**/*.ts"] } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy