Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/oxc_semantic/src/checker/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,20 @@ pub fn check_ts_module_declaration<'a>(decl: &TSModuleDeclaration<'a>, ctx: &Sem
check_ts_export_assignment_in_module_decl(decl, ctx);
}

fn global_scope_augmentation_should_have_declare_modifier(span: Span) -> OxcDiagnostic {
ts_error(
"2670",
"Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context.",
)
.with_label(span)
}

pub fn check_ts_global_declaration<'a>(decl: &TSGlobalDeclaration<'a>, ctx: &SemanticBuilder<'a>) {
check_ts_module_or_global_declaration(decl.span, ctx);

if !decl.declare && !ctx.in_declare_scope() {
ctx.error(global_scope_augmentation_should_have_declare_modifier(decl.global_span));
}
}

fn check_ts_module_or_global_declaration(span: Span, ctx: &SemanticBuilder<'_>) {
Expand Down
11 changes: 8 additions & 3 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: c21f73fd
parser_typescript Summary:
AST Parsed : 9832/9833 (99.99%)
Positive Passed: 9823/9833 (99.90%)
Negative Passed: 1485/2547 (58.30%)
Negative Passed: 1486/2547 (58.34%)
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration3.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration4.ts
Expand Down Expand Up @@ -654,8 +654,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/moduleAugmen

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/moduleAugmentationGlobal6.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/moduleAugmentationGlobal6_1.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/moduleAugmentationGlobal7.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/moduleAugmentationGlobal7_1.ts
Expand Down Expand Up @@ -8166,6 +8164,13 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────
help: Only 'readonly' modifier is allowed here.

× TS(2670): Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context.
╭─[typescript/tests/cases/compiler/moduleAugmentationGlobal6_1.ts:1:1]
1 │ global {
· ──────
2 │ interface Array<T> { x }
╰────

× Identifier `Kettle` has already been declared
╭─[typescript/tests/cases/compiler/moduleDuplicateIdentifiers.ts:20:14]
19 │
Expand Down
Loading