feat(parser): report error for initializer in ambient context (#19187)

This commit is contained in:
camc314 committed 2026-02-23 20:00:54 +00:00
1 parent 346045ae1e
commit c4a3677ad4
12 files changed
+518 -46

No files matched your search

@@ -23,5 +23,5 @@ declare global {
// Should preserve string modules as-is
declare module "test-module" {
export var d = 4;
export var d: 4;
}
@@ -21,5 +21,5 @@ declare global {
interface GlobalTest {}
}
declare module "test-module" {
var d = 4;
var d: 4;
}
@@ -1127,7 +1127,7 @@ fn test() {
"
declare module 'foo' {
type Test = 1;
const x: Test = 1;
const x: Test;
export = x;
}
",
@@ -2018,9 +2018,9 @@ fn test_d_ts() {
declare function func();
declare enum Enum {}
declare namespace Name {}
declare const v1 = 1;
declare var v2 = 1;
declare let v3 = 1;
declare const v1: 1;
declare var v2: 1;
declare let v3: 1;
declare const { v4 };
declare const { v4: v5 };
declare const [v6];
+2 -2
View File
@@ -187,7 +187,7 @@ fn test() {
("{ var foo = 1 }", None),
("if (true) { var foo = 1 }", None),
("var foo = 1", None),
("declare var foo = 2;", None),
("declare var foo: 2;", None),
("function foo() { var let; }", None),
("function foo() { var { let } = {}; }", None),
(
@@ -221,7 +221,7 @@ fn test() {
"function play(index: number) { if (index > 1) { var a = undefined } else { var a = undefined } console.log(a) }",
"function play(index: number) { if (index > 1) { var a = undefined } else { var a = undefined } console.log(a) }",
),
("declare var foo = 2;", "declare let foo = 2;"),
("declare var foo: 2;", "declare let foo: 2;"),
];
Tester::new(NoVar::NAME, NoVar::PLUGIN, pass, fail).expect_fix(fix).test_and_snapshot();
@@ -246,7 +246,7 @@ fn test() {
"class A { public static a = 1; }",
"class A { private static a = 1; }",
"class A { static readonly a = 1; }",
"class A { static declare a = 1; }",
// "class A { static declare a = 1; }",
"class A { static {}; }",
"class A2 { static #a() {}; }",
"class A2 { static #a = 1; }",
@@ -242,7 +242,7 @@ source: crates/oxc_linter/src/tester.rs
⚠ eslint(no-var): Unexpected var, use let or const instead.
╭─[no_var.tsx:1:9]
1 │ declare var foo = 2;
1 │ declare var foo: 2;
· ───
╰────
help: Replace var with let or const
+5
View File
@@ -1120,6 +1120,11 @@ pub fn implementation_in_ambient(span: Span) -> OxcDiagnostic {
ts_error("1183", "An implementation cannot be declared in ambient contexts.").with_label(span)
}
#[cold]
pub fn initializers_not_allowed_in_ambient_contexts(span: Span) -> OxcDiagnostic {
ts_error("1039", "Initializers are not allowed in ambient contexts.").with_label(span)
}
#[cold]
pub fn interface_implements(span: Span) -> OxcDiagnostic {
ts_error("1176", "Interface declaration cannot have 'implements' clause.").with_label(span)
+8
View File
@@ -661,6 +661,14 @@ impl<'a> ParserImpl<'a> {
});
self.error(diagnostics::abstract_property_cannot_have_initializer(name, span));
}
if self.ctx.has_ambient()
&& let Some(initializer) = &initializer
&& !(modifiers.contains(ModifierKind::Readonly) && type_annotation.is_none())
{
self.error(diagnostics::initializers_not_allowed_in_ambient_contexts(
initializer.span(),
));
}
self.ast.class_element_property_definition(
self.end_span(span),
r#type,
+6
View File
@@ -135,6 +135,12 @@ impl<'a> ParserImpl<'a> {
init,
definite.is_some(),
);
if self.ctx.has_ambient()
&& let Some(init) = &decl.init
&& !(decl.kind.is_const() && decl.type_annotation.is_none())
{
self.error(diagnostics::initializers_not_allowed_in_ambient_contexts(init.span()));
}
if decl_parent == VariableDeclarationParent::Statement {
self.check_missing_initializer(&decl);
}
@@ -24,11 +24,11 @@ Expected `{` but found `Identifier`
Mismatch: tasks/coverage/typescript/tests/cases/compiler/parenthesizedExpressionInternalComments.ts
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/reverseMappedTypeInferenceSameSource1.ts
An implementation cannot be declared in ambient contexts.
Initializers are not allowed in ambient contexts.An implementation cannot be declared in ambient contexts.
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/typeAssertionToGenericFunctionType.ts
Unexpected token
Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/controlFlow/controlFlowAssignmentPatternOrder.ts
An implementation cannot be declared in ambient contexts.
Initializers are not allowed in ambient contexts.Initializers are not allowed in ambient contexts.An implementation cannot be declared in ambient contexts.
Mismatch: tasks/coverage/typescript/tests/cases/conformance/es6/destructuring/destructuringReassignsRightHandSide.ts
Mismatch: tasks/coverage/typescript/tests/cases/conformance/es7/exponentiationOperator/emitExponentiationOperatorInTempalteString4.ts
+137 -15
View File
@@ -3,37 +3,23 @@ commit: ad32683b
parser_babel Summary:
AST Parsed : 2224/2224 (100.00%)
Positive Passed: 2211/2224 (99.42%)
Negative Passed: 1668/1689 (98.76%)
Negative Passed: 1675/1689 (99.17%)
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2026/explicit-resource-management/invalid-for-using-of-no-initializer/input.js
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/cast/unparenthesized-assert-and-assign/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/cast/unparenthesized-type-assertion-and-assign/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/declare-field-initializer/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/declare-initializer/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/declare-readonly-field-initializer-w-annotation/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/modifiers-incompatible/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-var/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/declare/module-class/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/declare/module-function/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/declare/namespace-class/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/declare/namespace-function/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/decorators/type-arguments-invalid/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/dts/invalid-class-implementation/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/dts/invalid-class-initializer/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/export/equals-in-script/input.ts
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/import/equals-in-script/input.ts
@@ -12390,6 +12376,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Allowed modifiers are: private, protected, public, static, abstract, override
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/accessor-invalid/input.ts:14:8]
13 │ accessor x = 1;
14 │ #y = 1;
· ─
15 │ }
╰────
× TS(1029): 'override' modifier must precede 'readonly' modifier.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/constructor-with-invalid-order-modifiers-1/input.ts:2:24]
1 │ class D extends B {
@@ -12463,6 +12457,22 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
4 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/declare-field-initializer/input.ts:2:25]
1 │ class A {
2 │ declare bar: string = "test";
· ──────
3 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/declare-initializer/input.ts:2:11]
1 │ declare class C {
2 │ field = "field";
· ───────
3 │ }
╰────
× TS(1031): 'declare' modifier cannot appear on class elements of this kind.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/declare-method/input.ts:2:3]
1 │ class A {
@@ -12488,6 +12498,22 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Try inserting a semicolon here
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/declare-readonly-field-initializer-w-annotation/input.ts:2:34]
1 │ class A {
2 │ declare readonly bar: string = "test";
· ──────
3 │ declare baz: string = "test";
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/declare-readonly-field-initializer-w-annotation/input.ts:3:25]
2 │ declare readonly bar: string = "test";
3 │ declare baz: string = "test";
· ──────
4 │ }
╰────
× TS(1030): 'declare' modifier already seen.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/duplicate-modifier-1/input.ts:2:18]
1 │ class A {
@@ -13143,6 +13169,22 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Add an initializer (e.g. ` = undefined`) here
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-await-using/input.ts:3:20]
2 │ await using A;
3 │ await using A1 = 0;
· ─
4 │ await using A2: number = 0;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-await-using/input.ts:4:28]
3 │ await using A1 = 0;
4 │ await using A2: number = 0;
· ─
5 │ await using B, C;
╰────
× Using declarations must have an initializer.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-await-using/input.ts:5:15]
4 │ await using A2: number = 0;
@@ -13170,6 +13212,22 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Add an initializer (e.g. ` = undefined`) here
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-using/input.ts:3:14]
2 │ using A;
3 │ using A1 = 0;
· ─
4 │ using A2: number = 0;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-using/input.ts:4:22]
3 │ using A1 = 0;
4 │ using A2: number = 0;
· ─
5 │ using B, C;
╰────
× Using declarations must have an initializer.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-using/input.ts:5:9]
4 │ using A2: number = 0;
@@ -13188,6 +13246,46 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Add an initializer (e.g. ` = undefined`) here
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-var/input.ts:2:11]
1 │ declare namespace invalid_namespace_var {
2 │ var A = 0;
· ─
3 │ var A1: number = 0;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-var/input.ts:3:20]
2 │ var A = 0;
3 │ var A1: number = 0;
· ─
4 │ let B = 0;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-var/input.ts:4:11]
3 │ var A1: number = 0;
4 │ let B = 0;
· ─
5 │ let B1: number = 0;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-var/input.ts:5:20]
4 │ let B = 0;
5 │ let B1: number = 0;
· ─
6 │ const C: number = 0;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-namespace-var/input.ts:6:21]
5 │ let B1: number = 0;
6 │ const C: number = 0;
· ─
7 │ }
╰────
× Expected a semicolon or an implicit semicolon after a statement, but found none
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/invalid-using-declaration/input.ts:1:8]
1 │ declare using basic;
@@ -13202,6 +13300,30 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Try inserting a semicolon here
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/module-class/input.ts:3:13]
2 │ class C {
3 │ field = "field";
· ───────
4 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/declare/namespace-class/input.ts:3:13]
2 │ class C {
3 │ field = "field";
· ───────
4 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/dts/invalid-class-initializer/input.ts:2:9]
1 │ class Foo {
2 │ foo = 3;
· ─
3 │ }
╰────
× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/typescript/expect-plugin/export-interface/input.js:1:8]
1 │ export interface Foo {}
+350 -19
View File
@@ -3,7 +3,7 @@ commit: ad04bf74
parser_typescript Summary:
AST Parsed : 9831/9834 (99.97%)
Positive Passed: 9820/9834 (99.86%)
Negative Passed: 1518/2578 (58.88%)
Negative Passed: 1527/2578 (59.23%)
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration3.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration4.ts
@@ -18,16 +18,12 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/allowSynthet
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ambientEnum1.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ambientErrors1.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ambientExportDefaultErrors.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ambientExternalModuleWithRelativeModuleName.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/ambientStatement1.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/amdDependencyCommentName4.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/anyIdenticalToItself.ts
@@ -158,8 +154,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constDeclara
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constDeclarations-access2.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constDeclarations-ambient-errors.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constEnumBadPropertyNames.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/constWithNonNull.ts
@@ -390,8 +384,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/extendGlobal
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/extendedInterfacesWithDuplicateTypeParameters.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/externSemantics.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/externalModuleImmutableBindings.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/externalModuleRefernceResolutionOrderInImportDeclaration.ts
@@ -638,8 +630,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/missingFunct
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/missingPropertiesOfClassExpression.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/missingRequiredDeclare.d.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/mixedStaticAndInstanceClassMembers.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/mixinPrivateAndProtected.ts
@@ -1360,8 +1350,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/esDecorat
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-nonStaticAmbient.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-staticAmbient.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/expressions/asOperator/asOperatorAmbiguity.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/expressions/assignmentOperator/compoundAdditionAssignmentLHSCanBeAssigned.ts
@@ -1490,8 +1478,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/externalM
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/externalModules/duplicateExportAssignments.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/externalModules/importTsBeforeDTs.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/externalModules/importsImplicitlyReadonly.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/externalModules/multipleExportDefault1.ts
@@ -1784,8 +1770,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ec
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnStatementInBlock1.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnStatementInBlock2.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnStatementInBlock3.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnStatementInBlock4.ts
@@ -1878,8 +1862,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ec
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserTryStatement1.d.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement2.d.ts
Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserWhileStatement1.d.ts
@@ -2930,6 +2912,12 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
5 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/ambientErrors1.ts:1:17]
1 │ declare var x = 4;
· ─
╰────
× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[typescript/tests/cases/compiler/ambientGetters.ts:6:18]
5 │ declare class B {
@@ -2947,6 +2935,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
7 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/ambientStatement1.ts:4:22]
3 │
4 │ export var v1 = () => false;
· ───────────
5 │ }
╰────
× Unexpected token
╭─[typescript/tests/cases/compiler/ambiguousGenericAssertion1.ts:4:10]
3 │ var r2 = < <T>(x: T) => T>f; // valid
@@ -3723,6 +3719,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
4 │ constructor() {
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/classExpressionPropertyModifiers.ts:2:36]
1 │ const a = class Cat {
2 │ declare [Symbol.toStringTag] = "uh";
· ────
3 │ export foo = 1;
╰────
× TS(1031): 'export' modifier cannot appear on class elements of this kind.
╭─[typescript/tests/cases/compiler/classExpressionPropertyModifiers.ts:3:5]
2 │ declare [Symbol.toStringTag] = "uh";
@@ -4546,6 +4550,46 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
22 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/constDeclarations-ambient-errors.ts:2:29]
1 │ // error: no intialization expected in ambient declarations
2 │ declare const c1: boolean = true;
· ────
3 │ declare const c2: number = 0;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/constDeclarations-ambient-errors.ts:3:28]
2 │ declare const c1: boolean = true;
3 │ declare const c2: number = 0;
· ─
4 │ declare const c3 = null, c4 :string = "", c5: any = 0;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/constDeclarations-ambient-errors.ts:4:39]
3 │ declare const c2: number = 0;
4 │ declare const c3 = null, c4 :string = "", c5: any = 0;
· ──
5 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/constDeclarations-ambient-errors.ts:4:53]
3 │ declare const c2: number = 0;
4 │ declare const c3 = null, c4 :string = "", c5: any = 0;
· ─
5 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/constDeclarations-ambient-errors.ts:8:24]
7 │ const c6 = 0;
8 │ const c7: number = 7;
· ─
9 │ }
╰────
× Missing initializer in const declaration
╭─[typescript/tests/cases/compiler/constDeclarations-errors.ts:2:7]
1 │ // error, missing intialicer
@@ -6368,6 +6412,20 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────
help: Try inserting a semicolon here
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/externSemantics.ts:1:15]
1 │ declare var x=10;
· ──
2 │ declare var v;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/externSemantics.ts:3:22]
2 │ declare var v;
3 │ declare var y:number=3;
· ─
╰────
× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[typescript/tests/cases/compiler/externSyntax.ts:8:20]
7 │ public f();
@@ -6741,6 +6799,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
2 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/illegalModifiersOnClassElements.ts:2:19]
1 │ class C {
2 │ declare foo = 1;
· ─
3 │ export bar = 1;
╰────
× TS(1031): 'export' modifier cannot appear on class elements of this kind.
╭─[typescript/tests/cases/compiler/illegalModifiersOnClassElements.ts:3:5]
2 │ declare foo = 1;
@@ -8179,6 +8245,12 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
49 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/missingRequiredDeclare.d.ts:1:9]
1 │ var x = 1;
· ─
╰────
× The only valid meta property for new is new.target
╭─[typescript/tests/cases/compiler/misspelledNewMetaProperty.ts:1:16]
1 │ function foo(){new.targ}
@@ -12481,6 +12553,141 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
· ─
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:8:18]
7 │ var a, b, c;
8 │ var a1, b1 = 10;
· ──
9 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:15:17]
14 │
15 │ declare var b = 10;
· ──
16 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:21:18]
20 │
21 │ declare var da = 10;
· ──
22 │ declare var d3, d4 = 10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:22:22]
21 │ declare var da = 10;
22 │ declare var d3, d4 = 10;
· ──
23 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:25:21]
24 │ namespace m3 {
25 │ declare var d = 10;
· ──
26 │ declare var d2, d3 = 10, d4 = 10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:26:26]
25 │ declare var d = 10;
26 │ declare var d2, d3 = 10, d4 = 10;
· ──
27 │ export declare var dE = 10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:26:35]
25 │ declare var d = 10;
26 │ declare var d2, d3 = 10, d4 = 10;
· ──
27 │ export declare var dE = 10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:27:29]
26 │ declare var d2, d3 = 10, d4 = 10;
27 │ export declare var dE = 10;
· ──
28 │ export declare var d2E, d3E = 10, d4E = 10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:28:35]
27 │ export declare var dE = 10;
28 │ export declare var d2E, d3E = 10, d4E = 10;
· ──
29 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:28:45]
27 │ export declare var dE = 10;
28 │ export declare var d2E, d3E = 10, d4E = 10;
· ──
29 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:32:13]
31 │ declare namespace m4 {
32 │ var d = 10;
· ──
33 │ var d2, d3 = 10, d4 =10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:33:18]
32 │ var d = 10;
33 │ var d2, d3 = 10, d4 =10;
· ──
34 │ export var dE = 10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:33:26]
32 │ var d = 10;
33 │ var d2, d3 = 10, d4 =10;
· ──
34 │ export var dE = 10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:34:21]
33 │ var d2, d3 = 10, d4 =10;
34 │ export var dE = 10;
· ──
35 │ export var d2E, d3E = 10, d4E = 10;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:35:27]
34 │ export var dE = 10;
35 │ export var d2E, d3E = 10, d4E = 10;
· ──
36 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:35:37]
34 │ export var dE = 10;
35 │ export var d2E, d3E = 10, d4E = 10;
· ──
36 │ }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/compiler/varBlock.ts:39:17]
38 │ declare var c;
39 │ declare var c = 10;
· ──
╰────
× TS(2369): A parameter property is only allowed in a constructor implementation.
╭─[typescript/tests/cases/compiler/varBlock.ts:11:22]
10 │ class C {
@@ -12545,6 +12752,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────
help: Either remove this `yield` or change the enclosing function to a generator function (`function*`)
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/ambient/ambientErrors.ts:2:17]
1 │ // Ambient variable with an initializer
2 │ declare var x = 4;
· ─
3 │
╰────
× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[typescript/tests/cases/conformance/ambient/ambientErrors.ts:20:24]
19 │ // Ambient function with function body
@@ -12553,6 +12768,30 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
21 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/ambient/ambientErrors.ts:34:13]
33 │ declare namespace M1 {
34 │ var x = 3;
· ─
35 │ function fn() { }
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/ambient/ambientErrors.ts:37:20]
36 │ class C {
37 │ static x = 3;
· ─
38 │ y = 4;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/ambient/ambientErrors.ts:38:13]
37 │ static x = 3;
38 │ y = 4;
· ─
39 │ constructor() { }
╰────
× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[typescript/tests/cases/conformance/ambient/ambientErrors.ts:39:23]
38 │ y = 4;
@@ -15652,6 +15891,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
16 │ declare nonce: any; // ok, even though it's not in the base
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts:17:24]
16 │ declare nonce: any; // ok, even though it's not in the base
17 │ declare property = 'y' // initialiser not allowed with declare
· ───
18 │ }
╰────
× TS(2391): Function implementation is missing or not immediately following the declaration.
╭─[typescript/tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionOverloadMixingStaticAndInstance.ts:3:12]
2 │ foo();
@@ -19505,6 +19752,30 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────
help: Allowed modifiers are: declare, abstract
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-staticAmbient.ts:6:37]
5 │ class C {
6 │ @dec(1) static declare field1 = 1;
· ─
7 │ @dec(2) static declare ["field2"] = 2;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-staticAmbient.ts:7:41]
6 │ @dec(1) static declare field1 = 1;
7 │ @dec(2) static declare ["field2"] = 2;
· ─
8 │ @dec(3) static declare [field3] = 3;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/esDecorators/classDeclaration/fields/esDecorators-classDeclaration-fields-staticAmbient.ts:8:39]
7 │ @dec(2) static declare ["field2"] = 2;
8 │ @dec(3) static declare [field3] = 3;
· ─
9 │ }
╰────
× TS(1249): A decorator can only decorate a method implementation, not an overload.
╭─[typescript/tests/cases/conformance/esDecorators/classDeclaration/methods/esDecorators-classDeclaration-methods-nonStaticAbstract.ts:6:5]
5 │ abstract class C {
@@ -20206,6 +20477,28 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
· ─
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/externalModules/importTsBeforeDTs.ts:1:24]
1 │ export var x: number = 42;
· ──
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/externalModules/initializersInDeclarations.ts:4:9]
3 │ declare class Foo {
4 │ name = "test";
· ──────
5 │ "some prop" = 42;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/externalModules/initializersInDeclarations.ts:5:16]
4 │ name = "test";
5 │ "some prop" = 42;
· ──
6 │ fn(): boolean {
╰────
× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[typescript/tests/cases/conformance/externalModules/initializersInDeclarations.ts:6:16]
5 │ "some prop" = 42;
@@ -20214,6 +20507,30 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
7 │ return false;
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/externalModules/initializersInDeclarations.ts:11:17]
10 │
11 │ declare var x = [];
· ──
12 │ declare var y = {};
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/externalModules/initializersInDeclarations.ts:12:17]
11 │ declare var x = [];
12 │ declare var y = {};
· ──
13 │
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/externalModules/initializersInDeclarations.ts:17:18]
16 │
17 │ export var v1 = () => false;
· ───────────
18 │ }
╰────
× Expected `as` but found `from`
╭─[typescript/tests/cases/conformance/externalModules/invalidSyntaxNamespaceImportWithAMD.ts:1:10]
1 │ import * from Zero from "./0"
@@ -22724,6 +23041,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────
help: Only 'readonly' modifier is allowed here.
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnStatementInBlock2.ts:2:20]
1 │ {
2 │ declare var x = this;
· ────
3 │ }
╰────
× Expected a semicolon or an implicit semicolon after a statement, but found none
╭─[typescript/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserPublicBreak1.ts:1:7]
1 │ public break;
@@ -24247,6 +24572,12 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
· ──────
╰────
× TS(1039): Initializers are not allowed in ambient contexts.
╭─[typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserVariableStatement1.d.ts:1:9]
1 │ var v = 1;
· ─
╰────
× 'with' statements are not allowed
╭─[typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts:1:1]
1 │ with (foo) {