diff --git a/crates/oxc_parser/src/js/declaration.rs b/crates/oxc_parser/src/js/declaration.rs index 4b870669b976c..5510aac59c16a 100644 --- a/crates/oxc_parser/src/js/declaration.rs +++ b/crates/oxc_parser/src/js/declaration.rs @@ -154,12 +154,7 @@ impl<'a> ParserImpl<'a> { self.error(diagnostics::invalid_destructuring_declaration(decl.id.span())); } else if decl.kind == VariableDeclarationKind::Const { // It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing this LexicalBinding is true. - self.error(diagnostics::missing_initializer_in_const( - decl.type_annotation.as_ref().map_or_else( - || decl.id.span(), - |type_annotation| decl.id.span().merge(type_annotation.span()), - ), - )); + self.error(diagnostics::missing_initializer_in_const(decl.id.span())); } } } @@ -197,10 +192,7 @@ impl<'a> ParserImpl<'a> { // Excluding `for` loops, an initializer is required in a UsingDeclaration. if declaration.init.is_none() && !matches!(statement_ctx, StatementContext::For) { self.error(diagnostics::using_declarations_must_be_initialized( - declaration.type_annotation.as_ref().map_or_else( - || declaration.id.span(), - |type_annotation| declaration.id.span().merge(type_annotation.span()), - ), + declaration.id.span(), )); } diff --git a/tasks/coverage/snapshots/parser_babel.snap b/tasks/coverage/snapshots/parser_babel.snap index 5e74df7b7f1a4..91f5bf776fec0 100644 --- a/tasks/coverage/snapshots/parser_babel.snap +++ b/tasks/coverage/snapshots/parser_babel.snap @@ -13257,14 +13257,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc × Missing initializer in const declaration ╭─[babel/packages/babel-parser/test/fixtures/typescript/const/no-initializer/input.ts:1:7] 1 │ const x: number; - · ───────── + · ─ ╰──── help: Add an initializer (e.g. ` = undefined`) here × Missing initializer in const declaration ╭─[babel/packages/babel-parser/test/fixtures/typescript/const/reserved-word/input.ts:1:7] 1 │ const b: const; - · ──────── + · ─ ╰──── help: Add an initializer (e.g. ` = undefined`) here diff --git a/tasks/coverage/snapshots/parser_typescript.snap b/tasks/coverage/snapshots/parser_typescript.snap index 316404553b5c0..e4d1841f38037 100644 --- a/tasks/coverage/snapshots/parser_typescript.snap +++ b/tasks/coverage/snapshots/parser_typescript.snap @@ -4448,7 +4448,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/compiler/constDeclarations-errors.ts:3:7] 2 │ const c1; 3 │ const c2: number; - · ────────── + · ── 4 │ const c3, c4, c5 :string, c6; // error, missing initialicer ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -4475,7 +4475,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/compiler/constDeclarations-errors.ts:4:15] 3 │ const c2: number; 4 │ const c3, c4, c5 :string, c6; // error, missing initialicer - · ────────── + · ── 5 │ ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -5108,7 +5108,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc × Missing initializer in const declaration ╭─[typescript/tests/cases/compiler/downlevelLetConst4.ts:1:7] 1 │ const a: number - · ───────── + · ─ ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -8721,7 +8721,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/compiler/numberVsBigIntOperations.ts:86:7] 85 │ const isNumber: (x: 0 | 1) => number = (x: 0 | 1) => x; 86 │ const zeroOrBigOne: 0 | 1n; - · ──────────────────── + · ──────────── 87 │ if (typeof zeroOrBigOne === "bigint") isBigInt(zeroOrBigOne); ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -8730,7 +8730,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/compiler/numberVsBigIntOperations.ts:93:7] 92 │ if (zeroOrBigOne) isOne(zeroOrBigOne); 93 │ const bigZeroOrOne: 0n | 1; - · ──────────────────── + · ──────────── 94 │ if (bigZeroOrOne) isOne(bigZeroOrOne); ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -12407,7 +12407,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/compiler/unusedLocalsInMethod4.ts:103:11] 102 │ function f9() { 103 │ const x: number; // should have only one error - · ───────── + · ─ 104 │ function bar() { ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -17097,7 +17097,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc × Missing initializer in const declaration ╭─[typescript/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts:1:7] 1 │ const a: number - · ───────── + · ─ ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -19559,7 +19559,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/externalModules/exportNonInitializedVariablesInIfThenStatementNoCrash1.ts:4:14] 3 │ if (true) 4 │ export const cssExports: CssExports; - · ────────────────────── + · ────────── 5 │ export default cssExports; ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -20663,7 +20663,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/jsx/jsxParsingErrorImmediateSpreadInAttributeValue.tsx:8:7] 7 │ 8 │ const X: any - · ────── + · ─ 9 │ const a: any ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -20672,7 +20672,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/jsx/jsxParsingErrorImmediateSpreadInAttributeValue.tsx:9:7] 8 │ const X: any 9 │ const a: any - · ────── + · ─ 10 │ ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -24397,7 +24397,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarations.16.ts:2:17] 1 │ declare namespace N { 2 │ await using x: { [Symbol.asyncDispose](): Promise }; - · ───────────────────────────────────────────── + · ─ 3 │ await using y: null; ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -24406,7 +24406,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarations.16.ts:3:17] 2 │ await using x: { [Symbol.asyncDispose](): Promise }; 3 │ await using y: null; - · ─────── + · ─ 4 │ } ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -24415,7 +24415,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarations.16.ts:6:17] 5 │ declare module 'M' { 6 │ await using x: { [Symbol.asyncDispose](): Promise }; - · ───────────────────────────────────────────── + · ─ 7 │ await using y: null; ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -24424,7 +24424,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarations.16.ts:7:17] 6 │ await using x: { [Symbol.asyncDispose](): Promise }; 7 │ await using y: null; - · ─────── + · ─ 8 │ } ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -24607,7 +24607,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.16.ts:2:11] 1 │ declare namespace N { 2 │ using x: { [Symbol.dispose](): void }; - · ─────────────────────────────── + · ─ 3 │ using y: null; ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -24616,7 +24616,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.16.ts:3:11] 2 │ using x: { [Symbol.dispose](): void }; 3 │ using y: null; - · ─────── + · ─ 4 │ } ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -24625,7 +24625,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.16.ts:6:11] 5 │ declare module 'M' { 6 │ using x: { [Symbol.dispose](): void }; - · ─────────────────────────────── + · ─ 7 │ using y: null; ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -24634,7 +24634,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.16.ts:7:11] 6 │ using x: { [Symbol.dispose](): void }; 7 │ using y: null; - · ─────── + · ─ 8 │ } ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -25154,7 +25154,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/labeledStatements/labeledStatementExportDeclarationNoCrash1.ts:3:14] 2 │ 3 │ export const box: string - · ─────────── + · ─── 4 │ subTitle: ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -25163,7 +25163,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/statements/labeledStatements/labeledStatementExportDeclarationNoCrash1.ts:5:14] 4 │ subTitle: 5 │ export const title: string - · ───────────── + · ───── ╰──── help: Add an initializer (e.g. ` = undefined`) here @@ -26381,7 +26381,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc ╭─[typescript/tests/cases/conformance/types/stringLiteral/stringLiteralTypesInVariableDeclarations01.ts:4:7] 3 │ let c: "bar"; 4 │ const d: "baz"; - · ──────── + · ─ 5 │ ╰──── help: Add an initializer (e.g. ` = undefined`) here