Skip to content

Commit 5631ebd

Browse files
committed
fix(ast/extree): fix TSModuleDeclaration.global (#9941)
This is a copy of #9907. For some reason Graphite bungled things up, and that PR got merged into the wrong branch. spec: https://github.com/typescript-eslint/typescript-eslint/blob/6428670b94de0027189803e5a291858d2e45362d/packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts#L26-L36 It looks like this is a deprecated property as its redundant. I thought of removing it in https://github.com/oxc-project/acorn-test262, but that means I need to modify 10K files there, so I went with fixing this side.
1 parent d668be6 commit 5631ebd

File tree

7 files changed

+19
-119
lines changed

7 files changed

+19
-119
lines changed

crates/oxc_ast/src/ast/ts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ pub enum TSTypePredicateName<'a> {
11231123
)]
11241124
#[derive(Debug)]
11251125
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
1126+
#[estree(add_fields(global = TSModuleDeclarationGlobal))]
11261127
pub struct TSModuleDeclaration<'a> {
11271128
pub span: Span,
11281129
/// The name of the module/namespace being declared.

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,7 @@ impl ESTree for TSModuleDeclaration<'_> {
30093009
state.serialize_field("body", &self.body);
30103010
state.serialize_field("kind", &self.kind);
30113011
state.serialize_field("declare", &self.declare);
3012+
state.serialize_field("global", &crate::serialize::TSModuleDeclarationGlobal(self));
30123013
state.end();
30133014
}
30143015
}

crates/oxc_ast/src/serialize.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,19 @@ impl ESTree for ClassImplements<'_, '_> {
558558
}
559559
}
560560

561+
#[ast_meta]
562+
#[estree(
563+
ts_type = "boolean",
564+
raw_deser = "DESER[TSModuleDeclarationKind](POS_OFFSET.kind) === 'global'"
565+
)]
566+
pub struct TSModuleDeclarationGlobal<'a, 'b>(pub &'b TSModuleDeclaration<'a>);
567+
568+
impl ESTree for TSModuleDeclarationGlobal<'_, '_> {
569+
fn serialize<S: Serializer>(&self, serializer: S) {
570+
self.0.kind.is_global().serialize(serializer);
571+
}
572+
}
573+
561574
// --------------------
562575
// JSX
563576
// --------------------

napi/parser/deserialize-js.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,7 @@ function deserializeTSModuleDeclaration(pos) {
17271727
body: deserializeOptionTSModuleDeclarationBody(pos + 64),
17281728
kind: deserializeTSModuleDeclarationKind(pos + 80),
17291729
declare: deserializeBool(pos + 81),
1730+
global: deserializeTSModuleDeclarationKind(pos + 80) === 'global',
17301731
};
17311732
}
17321733

napi/parser/deserialize-ts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,7 @@ function deserializeTSModuleDeclaration(pos) {
17911791
body: deserializeOptionTSModuleDeclarationBody(pos + 64),
17921792
kind: deserializeTSModuleDeclarationKind(pos + 80),
17931793
declare: deserializeBool(pos + 81),
1794+
global: deserializeTSModuleDeclarationKind(pos + 80) === 'global',
17941795
};
17951796
}
17961797

npm/oxc-types/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,7 @@ export interface TSModuleDeclaration extends Span {
12611261
body: TSModuleDeclarationBody | null;
12621262
kind: TSModuleDeclarationKind;
12631263
declare: boolean;
1264+
global: boolean;
12641265
}
12651266

12661267
export type TSModuleDeclarationKind = 'global' | 'module' | 'namespace';

tasks/coverage/snapshots/estree_typescript.snap

Lines changed: 1 addition & 119 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)