mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-14 22:29:17 +00:00
feat(ast)!: split TS external modules & Namespace Declarations (#25284)
## Summary
- Splits `TSModuleDeclaration` into two dedicated declaration nodes:
- `TSExternalModuleDeclaration` for string-literal modules and module augmentations.
- `TSNamespaceDeclaration` for identifier-based `module` and `namespace` declarations.
- Removes `TSModuleDeclaration`, `TSModuleDeclarationName`, `TSModuleDeclarationBody`, and `TSModuleDeclarationKind`.
- Makes invalid combinations of names, bodies, and declaration kinds unrepresentable.
- Ensures only namespace declarations introduce a normal binding.
- Updates all AST consumers, generators, traversal, formatting, code generation, semantic analysis, lint rules, transforms, and serialization.
- Keeps normal and eager-raw ESTree output compatible: both declarations remain `TSModuleDeclaration` nodes.
- Allows experimental lazy raw deserialization to expose the two new node types directly.
## Breaking Change
The Rust AST changes from:
```rust
pub enum Declaration<'a> {
VariableDeclaration(Box<'a, VariableDeclaration<'a>>) = 32,
FunctionDeclaration(Box<'a, Function<'a>>) = 33,
ClassDeclaration(Box<'a, Class<'a>>) = 34,
TSTypeAliasDeclaration(Box<'a, TSTypeAliasDeclaration<'a>>) = 35,
TSInterfaceDeclaration(Box<'a, TSInterfaceDeclaration<'a>>) = 36,
TSEnumDeclaration(Box<'a, TSEnumDeclaration<'a>>) = 37,
TSModuleDeclaration(Box<'a, TSModuleDeclaration<'a>>) = 38,
TSGlobalDeclaration(Box<'a, TSGlobalDeclaration<'a>>) = 39,
TSImportEqualsDeclaration(Box<'a, TSImportEqualsDeclaration<'a>>) = 40,
}
pub struct TSModuleDeclaration<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub id: TSModuleDeclarationName<'a>,
pub body: Option<TSModuleDeclarationBody<'a>>,
pub kind: TSModuleDeclarationKind,
pub declare: bool,
pub scope_id: Cell<Option<ScopeId>>,
}
```
to:
```rust
pub enum Declaration<'a> {
VariableDeclaration(Box<'a, VariableDeclaration<'a>>) = 32,
FunctionDeclaration(Box<'a, Function<'a>>) = 33,
ClassDeclaration(Box<'a, Class<'a>>) = 34,
TSTypeAliasDeclaration(Box<'a, TSTypeAliasDeclaration<'a>>) = 35,
TSInterfaceDeclaration(Box<'a, TSInterfaceDeclaration<'a>>) = 36,
TSEnumDeclaration(Box<'a, TSEnumDeclaration<'a>>) = 37,
TSExternalModuleDeclaration(Box<'a, TSExternalModuleDeclaration<'a>>) = 38,
TSNamespaceDeclaration(Box<'a, TSNamespaceDeclaration<'a>>) = 39,
TSGlobalDeclaration(Box<'a, TSGlobalDeclaration<'a>>) = 40,
TSImportEqualsDeclaration(Box<'a, TSImportEqualsDeclaration<'a>>) = 41,
}
pub struct TSExternalModuleDeclaration<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub id: StringLiteral<'a>,
pub body: Option<Box<'a, TSModuleBlock<'a>>>,
pub declare: bool,
pub scope_id: Cell<Option<ScopeId>>,
}
pub struct TSNamespaceDeclaration<'a> {
pub node_id: Cell<NodeId>,
pub span: Span,
pub id: BindingIdentifier<'a>,
pub body: TSNamespaceDeclarationBody<'a>,
pub kind: TSNamespaceDeclarationKind,
pub declare: bool,
pub scope_id: Cell<Option<ScopeId>>,
}
pub enum TSNamespaceDeclarationBody<'a> {
TSNamespaceDeclaration(Box<'a, TSNamespaceDeclaration<'a>>) = 0,
TSModuleBlock(Box<'a, TSModuleBlock<'a>>) = 1,
}
pub enum TSNamespaceDeclarationKind {
Module = 0,
Namespace = 1,
}
```
The corresponding inherited `Statement` variants, `AstKind` variants, builders, and visitor methods have also changed.
## Why?
`TSModuleDeclaration` previously represented two declaration families with different syntax and semantics:
```ts
declare module "foo" {}
declare module "*.css";
module Foo {}
namespace Foo {}
namespace Foo.Bar {}
```
The shared representation allowed invalid states such as:
- A namespace with a string-literal name.
- An external module with an identifier name.
- An identifier namespace without a body.
- A dotted external module.
- An external module containing another module declaration as its body.
- A declaration whose `kind` disagreed with its name.
Consumers also had to inspect `id` before determining whether the node introduced a binding or represented an external module.
The two declaration families have stronger independent invariants:
### External modules
- Always have a string-literal name.
- Never introduce a normal binding identifier.
- May omit their body.
- Cannot use dotted names.
- Use module-body import and export rules.
### Namespace declarations
- Always have a binding identifier.
- Always have a body.
- May contain nested namespace declarations for dotted names.
- Explicitly preserve the `module` or `namespace` spelling.
- Introduce a namespace/module symbol.
- Use namespace-body restrictions.
Dedicated nodes encode these differences directly.
## Declaration forms
External modules use `TSExternalModuleDeclaration`:
```ts
declare module "foo" {}
declare module "*.css";
module "foo" {}
```
Identifier-based declarations use `TSNamespaceDeclaration`:
```ts
module Foo {}
namespace Foo {}
```
Dotted namespaces are represented as nested namespace declarations:
```ts
namespace Foo.Bar {}
```
```rust
TSNamespaceDeclaration {
id: Foo,
body: TSNamespaceDeclarationBody::TSNamespaceDeclaration(
TSNamespaceDeclaration {
id: Bar,
body: TSNamespaceDeclarationBody::TSModuleBlock(...),
// ...
}
),
// ...
}
```
Only `TSExternalModuleDeclaration::body` is optional.
## ESTree compatibility
Normal serialization and eager raw deserialization continue to emit the existing ESTree shape:
```ts
interface TSModuleDeclaration {
type: "TSModuleDeclaration";
id: BindingIdentifier | StringLiteral | TSQualifiedName;
body: TSModuleBlock | null;
kind: "module" | "namespace";
declare: boolean;
global: false;
}
```
Dotted namespaces continue to serialize as a single `TSModuleDeclaration` with a `TSQualifiedName`.
Experimental lazy raw deserialization is not compatibility-preserving. It now exposes `TSExternalModuleDeclaration` and `TSNamespaceDeclaration` directly, with separate constructors, layouts, and visitor type IDs.
## How to migrate
Code that previously matched all forms through one variant:
```rust
if let Declaration::TSModuleDeclaration(declaration) = declaration {
// ...
}
```
should now match the required declaration family:
```rust
match declaration {
Declaration::TSExternalModuleDeclaration(declaration) => {
// String-literal external module
}
Declaration::TSNamespaceDeclaration(declaration) => {
// Identifier-based module or namespace
}
_ => {}
}
```
The same applies to `Statement` and `AstKind`:
```rust
Statement::TSExternalModuleDeclaration(declaration)
Statement::TSNamespaceDeclaration(declaration)
AstKind::TSExternalModuleDeclaration(declaration)
AstKind::TSNamespaceDeclaration(declaration)
```
Common field migrations:
| Previous representation | New representation |
| --- | --- |
| `TSModuleDeclarationName::StringLiteral(id)` | `TSExternalModuleDeclaration::id` |
| `TSModuleDeclarationName::Identifier(id)` | `TSNamespaceDeclaration::id` |
| `body: None` | Only valid on `TSExternalModuleDeclaration` |
| `TSModuleDeclarationBody::TSModuleBlock` | External `body` or `TSNamespaceDeclarationBody::TSModuleBlock` |
| `TSModuleDeclarationBody::TSModuleDeclaration` | `TSNamespaceDeclarationBody::TSNamespaceDeclaration` |
| `TSModuleDeclarationKind::Module` | External module, or `TSNamespaceDeclarationKind::Module` |
| `TSModuleDeclarationKind::Namespace` | `TSNamespaceDeclarationKind::Namespace` |
| Inspect `id` to determine binding behavior | Match `TSNamespaceDeclaration` |
| `declaration.id()` for string modules | Now returns `None` |
| `visit_ts_module_declaration` | `visit_ts_external_module_declaration` or `visit_ts_namespace_declaration` |
When constructing nodes, use the generated `TSExternalModuleDeclaration` or `TSNamespaceDeclaration` builders rather than recreating the previous shared representation.
fixes https://github.com/oxc-project/backlog/issues/218
This commit is contained in:
1 parent
9a7c323500
commit
44fd320324
103 files changed
+4504
-3593
No files matched your search
@@ -1512,10 +1512,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1590,10 +1592,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -5194,31 +5198,39 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
declare = deserializeBool(pos + 72),
|
||||
previousParent = parent,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
node = parent = {
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = (parent = {
|
||||
__proto__: NodeProto,
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
range: [start, end],
|
||||
parent,
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node = parent = {
|
||||
});
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
body !== null && (body.parent = node);
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
previousParent = parent,
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = (parent = {
|
||||
__proto__: NodeProto,
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
@@ -5230,98 +5242,84 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
end,
|
||||
range: [start, end],
|
||||
parent,
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start,
|
||||
end,
|
||||
outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
__proto__: NodeProto,
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let end,
|
||||
right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
}),
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start,
|
||||
end,
|
||||
outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
__proto__: NodeProto,
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
parent: innerId,
|
||||
};
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
} else body = null;
|
||||
let end,
|
||||
right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
{
|
||||
__proto__: NodeProto,
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
range: [start, end],
|
||||
parent: innerId,
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
}
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6509,8 +6507,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -7215,14 +7217,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1484,6 +1484,8 @@ export interface TSTypePredicate extends Span {
|
||||
|
||||
export type TSTypePredicateName = IdentifierName | TSThisType;
|
||||
|
||||
export type TSModuleDeclarationKind = "module" | "namespace";
|
||||
|
||||
export interface TSModuleDeclaration extends Span {
|
||||
type: "TSModuleDeclaration";
|
||||
id: BindingIdentifier | StringLiteral | TSQualifiedName;
|
||||
@@ -1494,8 +1496,6 @@ export interface TSModuleDeclaration extends Span {
|
||||
parent: Node;
|
||||
}
|
||||
|
||||
export type TSModuleDeclarationKind = "module" | "namespace";
|
||||
|
||||
export interface TSGlobalDeclaration extends Span {
|
||||
type: "TSModuleDeclaration";
|
||||
id: IdentifierName;
|
||||
|
||||
@@ -1167,9 +1167,10 @@ pub enum Declaration<'a> {
|
||||
TSTypeAliasDeclaration(Box<'a, TSTypeAliasDeclaration<'a>>) = 35,
|
||||
TSInterfaceDeclaration(Box<'a, TSInterfaceDeclaration<'a>>) = 36,
|
||||
TSEnumDeclaration(Box<'a, TSEnumDeclaration<'a>>) = 37,
|
||||
TSModuleDeclaration(Box<'a, TSModuleDeclaration<'a>>) = 38,
|
||||
TSGlobalDeclaration(Box<'a, TSGlobalDeclaration<'a>>) = 39,
|
||||
TSImportEqualsDeclaration(Box<'a, TSImportEqualsDeclaration<'a>>) = 40,
|
||||
TSExternalModuleDeclaration(Box<'a, TSExternalModuleDeclaration<'a>>) = 38,
|
||||
TSNamespaceDeclaration(Box<'a, TSNamespaceDeclaration<'a>>) = 39,
|
||||
TSGlobalDeclaration(Box<'a, TSGlobalDeclaration<'a>>) = 40,
|
||||
TSImportEqualsDeclaration(Box<'a, TSImportEqualsDeclaration<'a>>) = 41,
|
||||
}
|
||||
|
||||
/// `let a;` in `let a; a = 1;`
|
||||
|
||||
@@ -1210,50 +1210,77 @@ pub enum TSTypePredicateName<'a> {
|
||||
This(Box<'a, TSThisType>) = 1,
|
||||
}
|
||||
|
||||
/// TypeScript Module and Namespace Declarations
|
||||
/// TypeScript external module declaration.
|
||||
///
|
||||
/// ## Examples
|
||||
/// ```ts
|
||||
/// declare module 'foo' { }
|
||||
/// // kind ^^^^^^ ^^^^^ id
|
||||
/// declare module '*.css';
|
||||
/// ```
|
||||
///
|
||||
/// ```ts
|
||||
/// namespace Foo { }
|
||||
/// declare namespace Bar { }
|
||||
/// // kind ^^^^^^^^^ ^^^ id
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// * [TypeScript Handbook - Namespaces](https://www.typescriptlang.org/docs/handbook/2/modules.html#namespaces)
|
||||
/// * [TypeScript Handbook - Module Augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation)
|
||||
#[ast(visit)]
|
||||
#[scope(
|
||||
flags = ScopeFlags::TsModuleBlock,
|
||||
strict_if = self.body.as_ref().is_some_and(TSModuleDeclarationBody::has_use_strict_directive),
|
||||
strict_if = self.body.as_ref().is_some_and(|body| body.has_use_strict_directive()),
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
#[generate_derive(CloneIn, Dummy, ReplaceWith, TakeIn)]
|
||||
#[generate_derive(ContentEq, ESTree, GetSpan, GetSpanMut, UnstableAddress)]
|
||||
#[estree(via = TSModuleDeclarationConverter, add_fields(global = False))]
|
||||
pub struct TSModuleDeclaration<'a> {
|
||||
#[estree(
|
||||
rename = "TSModuleDeclaration",
|
||||
ts_alias = "TSModuleDeclaration",
|
||||
via = TSExternalModuleDeclarationConverter,
|
||||
add_ts_def = "
|
||||
type TSModuleDeclarationKind = 'module' | 'namespace';
|
||||
|
||||
export interface TSModuleDeclaration extends Span {
|
||||
type: 'TSModuleDeclaration';
|
||||
id: BindingIdentifier | StringLiteral | TSQualifiedName;
|
||||
body: TSModuleBlock | null;
|
||||
kind: TSModuleDeclarationKind;
|
||||
declare: boolean;
|
||||
global: false;
|
||||
parent/* IF !LINTER */?/* END IF */: Node;
|
||||
}
|
||||
"
|
||||
)]
|
||||
pub struct TSExternalModuleDeclaration<'a> {
|
||||
pub node_id: Cell<NodeId>,
|
||||
pub span: Span,
|
||||
/// The name of the module/namespace being declared.
|
||||
#[estree(ts_type = "BindingIdentifier | StringLiteral | TSQualifiedName")]
|
||||
pub id: TSModuleDeclarationName<'a>,
|
||||
pub id: StringLiteral<'a>,
|
||||
#[scope(enter_before)]
|
||||
#[estree(ts_type = "TSModuleBlock | null")]
|
||||
pub body: Option<TSModuleDeclarationBody<'a>>,
|
||||
/// The keyword used to define this module declaration.
|
||||
///
|
||||
/// ```ts
|
||||
/// namespace Foo {}
|
||||
/// ^^^^^^^^^
|
||||
/// module 'foo' {}
|
||||
/// ^^^^^^
|
||||
/// ```
|
||||
pub kind: TSModuleDeclarationKind,
|
||||
pub body: Option<Box<'a, TSModuleBlock<'a>>>,
|
||||
pub declare: bool,
|
||||
pub scope_id: Cell<Option<ScopeId>>,
|
||||
}
|
||||
|
||||
/// TypeScript namespace or identifier-based module declaration.
|
||||
///
|
||||
/// ## Examples
|
||||
/// ```ts
|
||||
/// module Foo { }
|
||||
/// namespace Bar { }
|
||||
/// namespace Foo.Bar { }
|
||||
/// ```
|
||||
#[ast(visit)]
|
||||
#[scope(
|
||||
flags = ScopeFlags::TsModuleBlock,
|
||||
strict_if = self.body.has_use_strict_directive(),
|
||||
)]
|
||||
#[derive(Debug)]
|
||||
#[generate_derive(CloneIn, Dummy, ReplaceWith, TakeIn)]
|
||||
#[generate_derive(ContentEq, ESTree, GetSpan, GetSpanMut, UnstableAddress)]
|
||||
#[estree(
|
||||
rename = "TSModuleDeclaration",
|
||||
ts_alias = "TSModuleDeclaration",
|
||||
via = TSNamespaceDeclarationConverter
|
||||
)]
|
||||
pub struct TSNamespaceDeclaration<'a> {
|
||||
pub node_id: Cell<NodeId>,
|
||||
pub span: Span,
|
||||
pub id: BindingIdentifier<'a>,
|
||||
#[scope(enter_before)]
|
||||
pub body: TSNamespaceDeclarationBody<'a>,
|
||||
pub kind: TSNamespaceDeclarationKind,
|
||||
pub declare: bool,
|
||||
pub scope_id: Cell<Option<ScopeId>>,
|
||||
}
|
||||
@@ -1261,49 +1288,21 @@ pub struct TSModuleDeclaration<'a> {
|
||||
#[ast]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[generate_derive(CloneIn, Dummy, ContentEq, ESTree)]
|
||||
pub enum TSModuleDeclarationKind {
|
||||
/// `module Foo {}`, `declare module 'foo' {}`
|
||||
#[estree(no_ts_def)]
|
||||
pub enum TSNamespaceDeclarationKind {
|
||||
/// `module Foo {}`
|
||||
Module = 0,
|
||||
/// `namespace Foo {}`
|
||||
Namespace = 1,
|
||||
}
|
||||
|
||||
/// The name of a TypeScript [namespace or module declaration](TSModuleDeclaration).
|
||||
///
|
||||
/// Note that it is a syntax error for namespace declarations to have a string literal name.
|
||||
/// Modules may have either kind.
|
||||
///
|
||||
/// ## Examples
|
||||
/// ```ts
|
||||
/// // TSModuleDeclarationName::StringLiteral
|
||||
/// declare module "*.css" {
|
||||
/// const styles: { [key: string]: string };
|
||||
/// export default styles;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```ts
|
||||
/// // TSModuleDeclarationName::Identifier
|
||||
/// namespace Foo {
|
||||
/// export const bar = 42;
|
||||
/// }
|
||||
/// ```
|
||||
#[ast(visit)]
|
||||
#[derive(Debug)]
|
||||
#[generate_derive(CloneIn, Dummy, ReplaceWith, TakeIn, ContentEq, ESTree, GetSpan, GetSpanMut)]
|
||||
#[estree(no_ts_def)]
|
||||
pub enum TSModuleDeclarationName<'a> {
|
||||
Identifier(BindingIdentifier<'a>) = 0,
|
||||
StringLiteral(StringLiteral<'a>) = 1,
|
||||
}
|
||||
|
||||
#[ast(visit)]
|
||||
#[derive(Debug)]
|
||||
#[generate_derive(CloneIn, Dummy, ReplaceWith, TakeIn)]
|
||||
#[generate_derive(ContentEq, ESTree, GetAddress, GetSpan, GetSpanMut)]
|
||||
#[estree(no_ts_def)]
|
||||
pub enum TSModuleDeclarationBody<'a> {
|
||||
TSModuleDeclaration(Box<'a, TSModuleDeclaration<'a>>) = 0,
|
||||
pub enum TSNamespaceDeclarationBody<'a> {
|
||||
TSNamespaceDeclaration(Box<'a, TSNamespaceDeclaration<'a>>) = 0,
|
||||
TSModuleBlock(Box<'a, TSModuleBlock<'a>>) = 1,
|
||||
}
|
||||
|
||||
@@ -1342,7 +1341,8 @@ pub struct TSGlobalDeclaration<'a> {
|
||||
pub scope_id: Cell<Option<ScopeId>>,
|
||||
}
|
||||
|
||||
/// Body block of a [`TSModuleDeclaration`] or [`TSGlobalDeclaration`].
|
||||
/// Body block of a [`TSExternalModuleDeclaration`], [`TSNamespaceDeclaration`], or
|
||||
/// [`TSGlobalDeclaration`].
|
||||
#[ast(visit)]
|
||||
#[derive(Debug)]
|
||||
#[generate_derive(CloneIn, Dummy, ReplaceWith, TakeIn)]
|
||||
|
||||
@@ -1129,14 +1129,10 @@ impl<'a> Declaration<'a> {
|
||||
Declaration::TSInterfaceDeclaration(decl) => Some(&decl.id),
|
||||
Declaration::TSEnumDeclaration(decl) => Some(&decl.id),
|
||||
Declaration::TSImportEqualsDeclaration(decl) => Some(&decl.id),
|
||||
Declaration::TSModuleDeclaration(decl) => {
|
||||
if let TSModuleDeclarationName::Identifier(ident) = &decl.id {
|
||||
Some(ident)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Declaration::TSGlobalDeclaration(_) | Declaration::VariableDeclaration(_) => None,
|
||||
Declaration::TSNamespaceDeclaration(decl) => Some(&decl.id),
|
||||
Declaration::TSExternalModuleDeclaration(_)
|
||||
| Declaration::TSGlobalDeclaration(_)
|
||||
| Declaration::VariableDeclaration(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1148,7 +1144,8 @@ impl<'a> Declaration<'a> {
|
||||
Declaration::ClassDeclaration(decl) => decl.declare,
|
||||
Declaration::TSEnumDeclaration(decl) => decl.declare,
|
||||
Declaration::TSTypeAliasDeclaration(decl) => decl.declare,
|
||||
Declaration::TSModuleDeclaration(decl) => decl.declare,
|
||||
Declaration::TSExternalModuleDeclaration(decl) => decl.declare,
|
||||
Declaration::TSNamespaceDeclaration(decl) => decl.declare,
|
||||
Declaration::TSGlobalDeclaration(decl) => decl.declare,
|
||||
Declaration::TSInterfaceDeclaration(decl) => decl.declare,
|
||||
Declaration::TSImportEqualsDeclaration(_) => false,
|
||||
|
||||
@@ -168,11 +168,18 @@ impl fmt::Display for TSAccessibility {
|
||||
}
|
||||
}
|
||||
|
||||
impl TSModuleDeclaration<'_> {
|
||||
impl TSExternalModuleDeclaration<'_> {
|
||||
/// Returns `true` if this module's body exists and has a `"use strict"` directive.
|
||||
pub fn has_use_strict_directive(&self) -> bool {
|
||||
self.body.as_ref().is_some_and(|body| body.has_use_strict_directive())
|
||||
}
|
||||
}
|
||||
|
||||
impl TSNamespaceDeclaration<'_> {
|
||||
/// Returns `true` if this namespace's body has a `"use strict"` directive.
|
||||
///
|
||||
/// Note that for a nested [`TSModuleDeclaration`], only returns `true` for the innermost `TSModuleDeclaration`.
|
||||
/// e.g. this AST has 3 x `TSModuleDeclaration`s:
|
||||
/// Note that for a nested [`TSNamespaceDeclaration`], only returns `true` for the innermost
|
||||
/// declaration. e.g. this AST has 3 x `TSNamespaceDeclaration`s:
|
||||
/// ```ts
|
||||
/// namespace X.Y.Z {
|
||||
/// "use strict";
|
||||
@@ -180,11 +187,11 @@ impl TSModuleDeclaration<'_> {
|
||||
/// ```
|
||||
/// This method will only return `true` for the innermost one (`Z`).
|
||||
pub fn has_use_strict_directive(&self) -> bool {
|
||||
self.body.as_ref().is_some_and(TSModuleDeclarationBody::has_use_strict_directive)
|
||||
self.body.has_use_strict_directive()
|
||||
}
|
||||
}
|
||||
|
||||
impl TSModuleDeclarationKind {
|
||||
impl TSNamespaceDeclarationKind {
|
||||
/// Declaration keyword as a string, identical to how it would appear in the
|
||||
/// source code.
|
||||
pub fn as_str(self) -> &'static str {
|
||||
@@ -195,48 +202,11 @@ impl TSModuleDeclarationKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TSModuleDeclarationName<'a> {
|
||||
/// Returns `true` if this name is a string literal.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```ts
|
||||
/// // true
|
||||
/// module "*.less" {
|
||||
/// const styles: { [key: string]: string };
|
||||
/// export default styles;
|
||||
/// }
|
||||
///
|
||||
/// // false
|
||||
/// module bar {}
|
||||
/// namespace bang {}
|
||||
/// ```
|
||||
pub fn is_string_literal(&self) -> bool {
|
||||
matches!(self, Self::StringLiteral(_))
|
||||
}
|
||||
|
||||
/// Get the static name of this module declaration name.
|
||||
pub fn name(&self) -> Str<'a> {
|
||||
match self {
|
||||
Self::Identifier(ident) => ident.name.into(),
|
||||
Self::StringLiteral(lit) => lit.value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for TSModuleDeclarationName<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Identifier(id) => id.fmt(f),
|
||||
Self::StringLiteral(lit) => lit.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TSModuleDeclarationBody<'a> {
|
||||
impl<'a> TSNamespaceDeclarationBody<'a> {
|
||||
/// Returns `true` if this module has a `"use strict"` directive.
|
||||
///
|
||||
/// Note that for a nested [`TSModuleDeclaration`], only returns `true` for the innermost [`TSModuleDeclarationBody`].
|
||||
/// e.g. this AST has 3 x `TSModuleDeclarationBody`s:
|
||||
/// Note that for a nested [`TSNamespaceDeclaration`], only returns `true` for the innermost
|
||||
/// [`TSNamespaceDeclarationBody`]. e.g. this AST has 3 x `TSNamespaceDeclarationBody`s:
|
||||
/// ```ts
|
||||
/// namespace X.Y.Z {
|
||||
/// "use strict";
|
||||
@@ -250,8 +220,10 @@ impl<'a> TSModuleDeclarationBody<'a> {
|
||||
/// Returns `true` if this module contains no statements.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
match self {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(declaration) => declaration.body.is_none(),
|
||||
TSModuleDeclarationBody::TSModuleBlock(block) => block.body.len() == 0,
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(declaration) => {
|
||||
declaration.body.is_empty()
|
||||
}
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => block.body.is_empty(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,9 +233,9 @@ impl<'a> TSModuleDeclarationBody<'a> {
|
||||
let mut body = self;
|
||||
loop {
|
||||
match body {
|
||||
TSModuleDeclarationBody::TSModuleBlock(block) => return Some(block.as_mut()),
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(decl) => {
|
||||
body = decl.body.as_mut()?;
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => return Some(block.as_mut()),
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(decl) => {
|
||||
body = &mut decl.body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ impl<'a> AstKind<'a> {
|
||||
pub fn is_declaration(self) -> bool {
|
||||
matches!(self, Self::Function(func) if func.is_declaration())
|
||||
|| matches!(self, Self::Class(class) if class.is_declaration())
|
||||
|| matches!(self, Self::TSEnumDeclaration(_) | Self::TSModuleDeclaration(_) | Self::TSGlobalDeclaration(_)
|
||||
|| matches!(self, Self::TSEnumDeclaration(_) | Self::TSExternalModuleDeclaration(_)
|
||||
| Self::TSNamespaceDeclaration(_) | Self::TSGlobalDeclaration(_)
|
||||
| Self::VariableDeclaration(_) | Self::TSInterfaceDeclaration(_)
|
||||
| Self::TSTypeAliasDeclaration(_) | Self::TSImportEqualsDeclaration(_) | Self::PropertyDefinition(_)
|
||||
) || self.is_module_declaration()
|
||||
@@ -589,7 +590,10 @@ impl AstKind<'_> {
|
||||
Self::TSQualifiedName(n) => format!("TSQualifiedName({n})").into(),
|
||||
Self::TSInterfaceDeclaration(_) => "TSInterfaceDeclaration".into(),
|
||||
Self::TSInterfaceHeritage(_) => "TSInterfaceHeritage".into(),
|
||||
Self::TSModuleDeclaration(m) => format!("TSModuleDeclaration({})", m.id).into(),
|
||||
Self::TSExternalModuleDeclaration(m) => {
|
||||
format!("TSExternalModuleDeclaration({})", m.id).into()
|
||||
}
|
||||
Self::TSNamespaceDeclaration(m) => format!("TSNamespaceDeclaration({})", m.id).into(),
|
||||
Self::TSGlobalDeclaration(_) => "TSGlobalDeclaration".into(),
|
||||
Self::TSTypeAliasDeclaration(_) => "TSTypeAliasDeclaration".into(),
|
||||
Self::TSTypeAnnotation(_) => "TSTypeAnnotation".into(),
|
||||
|
||||
@@ -1580,25 +1580,32 @@ const _: () = {
|
||||
assert!(size_of::<TSTypePredicateName>() == 16);
|
||||
assert!(align_of::<TSTypePredicateName>() == 8);
|
||||
|
||||
// Padding: 7 bytes
|
||||
assert!(size_of::<TSExternalModuleDeclaration>() == 80);
|
||||
assert!(align_of::<TSExternalModuleDeclaration>() == 8);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, span) == 0);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, node_id) == 8);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, scope_id) == 12);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, id) == 16);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, body) == 64);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, declare) == 72);
|
||||
|
||||
// Padding: 6 bytes
|
||||
assert!(size_of::<TSModuleDeclaration>() == 96);
|
||||
assert!(align_of::<TSModuleDeclaration>() == 8);
|
||||
assert!(offset_of!(TSModuleDeclaration, span) == 0);
|
||||
assert!(offset_of!(TSModuleDeclaration, node_id) == 8);
|
||||
assert!(offset_of!(TSModuleDeclaration, scope_id) == 12);
|
||||
assert!(offset_of!(TSModuleDeclaration, id) == 16);
|
||||
assert!(offset_of!(TSModuleDeclaration, body) == 72);
|
||||
assert!(offset_of!(TSModuleDeclaration, kind) == 88);
|
||||
assert!(offset_of!(TSModuleDeclaration, declare) == 89);
|
||||
assert!(size_of::<TSNamespaceDeclaration>() == 72);
|
||||
assert!(align_of::<TSNamespaceDeclaration>() == 8);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, span) == 0);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, node_id) == 8);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, scope_id) == 12);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, id) == 16);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, body) == 48);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, kind) == 64);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, declare) == 65);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationKind>() == 1);
|
||||
assert!(align_of::<TSModuleDeclarationKind>() == 1);
|
||||
assert!(size_of::<TSNamespaceDeclarationKind>() == 1);
|
||||
assert!(align_of::<TSNamespaceDeclarationKind>() == 1);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationName>() == 56);
|
||||
assert!(align_of::<TSModuleDeclarationName>() == 8);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationBody>() == 16);
|
||||
assert!(align_of::<TSModuleDeclarationBody>() == 8);
|
||||
assert!(size_of::<TSNamespaceDeclarationBody>() == 16);
|
||||
assert!(align_of::<TSNamespaceDeclarationBody>() == 8);
|
||||
|
||||
// Padding: 7 bytes
|
||||
assert!(size_of::<TSGlobalDeclaration>() == 96);
|
||||
@@ -3411,25 +3418,32 @@ const _: () = if cfg!(target_family = "wasm") || align_of::<u64>() == 8 {
|
||||
assert!(size_of::<TSTypePredicateName>() == 8);
|
||||
assert!(align_of::<TSTypePredicateName>() == 4);
|
||||
|
||||
// Padding: 3 bytes
|
||||
assert!(size_of::<TSExternalModuleDeclaration>() == 56);
|
||||
assert!(align_of::<TSExternalModuleDeclaration>() == 4);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, span) == 0);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, node_id) == 8);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, scope_id) == 12);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, id) == 16);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, body) == 48);
|
||||
assert!(offset_of!(TSExternalModuleDeclaration, declare) == 52);
|
||||
|
||||
// Padding: 2 bytes
|
||||
assert!(size_of::<TSModuleDeclaration>() == 64);
|
||||
assert!(align_of::<TSModuleDeclaration>() == 4);
|
||||
assert!(offset_of!(TSModuleDeclaration, span) == 0);
|
||||
assert!(offset_of!(TSModuleDeclaration, node_id) == 8);
|
||||
assert!(offset_of!(TSModuleDeclaration, scope_id) == 12);
|
||||
assert!(offset_of!(TSModuleDeclaration, id) == 16);
|
||||
assert!(offset_of!(TSModuleDeclaration, body) == 52);
|
||||
assert!(offset_of!(TSModuleDeclaration, kind) == 60);
|
||||
assert!(offset_of!(TSModuleDeclaration, declare) == 61);
|
||||
assert!(size_of::<TSNamespaceDeclaration>() == 56);
|
||||
assert!(align_of::<TSNamespaceDeclaration>() == 4);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, span) == 0);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, node_id) == 8);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, scope_id) == 12);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, id) == 16);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, body) == 44);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, kind) == 52);
|
||||
assert!(offset_of!(TSNamespaceDeclaration, declare) == 53);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationKind>() == 1);
|
||||
assert!(align_of::<TSModuleDeclarationKind>() == 1);
|
||||
assert!(size_of::<TSNamespaceDeclarationKind>() == 1);
|
||||
assert!(align_of::<TSNamespaceDeclarationKind>() == 1);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationName>() == 36);
|
||||
assert!(align_of::<TSModuleDeclarationName>() == 4);
|
||||
|
||||
assert!(size_of::<TSModuleDeclarationBody>() == 8);
|
||||
assert!(align_of::<TSModuleDeclarationBody>() == 4);
|
||||
assert!(size_of::<TSNamespaceDeclarationBody>() == 8);
|
||||
assert!(align_of::<TSNamespaceDeclarationBody>() == 4);
|
||||
|
||||
// Padding: 3 bytes
|
||||
assert!(size_of::<TSGlobalDeclaration>() == 72);
|
||||
|
||||
@@ -8855,26 +8855,81 @@ impl<'a> Statement<'a> {
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`Statement::TSModuleDeclaration`].
|
||||
/// Build a [`Statement::TSExternalModuleDeclaration`].
|
||||
///
|
||||
/// This node contains a [`TSModuleDeclaration`] that will be stored in the memory arena.
|
||||
/// This node contains a [`TSExternalModuleDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn new_ts_module_declaration(
|
||||
pub fn new_ts_external_module_declaration(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: StringLiteral<'a>,
|
||||
body: Option<ArenaBox<'a, TSModuleBlock<'a>>>,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSModuleDeclaration(TSModuleDeclaration::boxed(
|
||||
Self::TSExternalModuleDeclaration(TSExternalModuleDeclaration::boxed(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
declare,
|
||||
builder.builder(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`Statement::TSExternalModuleDeclaration`] with `scope_id`.
|
||||
///
|
||||
/// This node contains a [`TSExternalModuleDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn new_ts_external_module_declaration_with_scope_id(
|
||||
span: Span,
|
||||
id: StringLiteral<'a>,
|
||||
body: Option<ArenaBox<'a, TSModuleBlock<'a>>>,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSExternalModuleDeclaration(TSExternalModuleDeclaration::boxed_with_scope_id(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
declare,
|
||||
scope_id,
|
||||
builder.builder(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`Statement::TSNamespaceDeclaration`].
|
||||
///
|
||||
/// This node contains a [`TSNamespaceDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn new_ts_namespace_declaration(
|
||||
span: Span,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSNamespaceDeclaration(TSNamespaceDeclaration::boxed(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
@@ -8884,28 +8939,28 @@ impl<'a> Statement<'a> {
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`Statement::TSModuleDeclaration`] with `scope_id`.
|
||||
/// Build a [`Statement::TSNamespaceDeclaration`] with `scope_id`.
|
||||
///
|
||||
/// This node contains a [`TSModuleDeclaration`] that will be stored in the memory arena.
|
||||
/// This node contains a [`TSNamespaceDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn new_ts_module_declaration_with_scope_id(
|
||||
pub fn new_ts_namespace_declaration_with_scope_id(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSModuleDeclaration(TSModuleDeclaration::boxed_with_scope_id(
|
||||
Self::TSNamespaceDeclaration(TSNamespaceDeclaration::boxed_with_scope_id(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
@@ -9695,26 +9750,81 @@ impl<'a> Declaration<'a> {
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`Declaration::TSModuleDeclaration`].
|
||||
/// Build a [`Declaration::TSExternalModuleDeclaration`].
|
||||
///
|
||||
/// This node contains a [`TSModuleDeclaration`] that will be stored in the memory arena.
|
||||
/// This node contains a [`TSExternalModuleDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn new_ts_module_declaration(
|
||||
pub fn new_ts_external_module_declaration(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: StringLiteral<'a>,
|
||||
body: Option<ArenaBox<'a, TSModuleBlock<'a>>>,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSModuleDeclaration(TSModuleDeclaration::boxed(
|
||||
Self::TSExternalModuleDeclaration(TSExternalModuleDeclaration::boxed(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
declare,
|
||||
builder.builder(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`Declaration::TSExternalModuleDeclaration`] with `scope_id`.
|
||||
///
|
||||
/// This node contains a [`TSExternalModuleDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn new_ts_external_module_declaration_with_scope_id(
|
||||
span: Span,
|
||||
id: StringLiteral<'a>,
|
||||
body: Option<ArenaBox<'a, TSModuleBlock<'a>>>,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSExternalModuleDeclaration(TSExternalModuleDeclaration::boxed_with_scope_id(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
declare,
|
||||
scope_id,
|
||||
builder.builder(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`Declaration::TSNamespaceDeclaration`].
|
||||
///
|
||||
/// This node contains a [`TSNamespaceDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn new_ts_namespace_declaration(
|
||||
span: Span,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSNamespaceDeclaration(TSNamespaceDeclaration::boxed(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
@@ -9724,28 +9834,28 @@ impl<'a> Declaration<'a> {
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`Declaration::TSModuleDeclaration`] with `scope_id`.
|
||||
/// Build a [`Declaration::TSNamespaceDeclaration`] with `scope_id`.
|
||||
///
|
||||
/// This node contains a [`TSModuleDeclaration`] that will be stored in the memory arena.
|
||||
/// This node contains a [`TSNamespaceDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn new_ts_module_declaration_with_scope_id(
|
||||
pub fn new_ts_namespace_declaration_with_scope_id(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSModuleDeclaration(TSModuleDeclaration::boxed_with_scope_id(
|
||||
Self::TSNamespaceDeclaration(TSNamespaceDeclaration::boxed_with_scope_id(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
@@ -25373,29 +25483,140 @@ impl<'a> TSTypePredicateName<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TSModuleDeclaration<'a> {
|
||||
/// Build a [`TSModuleDeclaration`].
|
||||
impl<'a> TSExternalModuleDeclaration<'a> {
|
||||
/// Build a [`TSExternalModuleDeclaration`].
|
||||
///
|
||||
/// If you want the built node to be allocated in the memory arena,
|
||||
/// use [`TSModuleDeclaration::boxed`] instead.
|
||||
/// use [`TSExternalModuleDeclaration::boxed`] instead.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn new(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: StringLiteral<'a>,
|
||||
body: Option<ArenaBox<'a, TSModuleBlock<'a>>>,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
let builder = builder.builder();
|
||||
TSModuleDeclaration {
|
||||
TSExternalModuleDeclaration {
|
||||
node_id: Cell::new(builder.node_id()),
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
declare,
|
||||
scope_id: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a [`TSExternalModuleDeclaration`], and store it in the memory arena.
|
||||
///
|
||||
/// Returns a [`Box`](ArenaBox) containing the newly-allocated node.
|
||||
/// If you want a stack-allocated node, use [`TSExternalModuleDeclaration::new`] instead.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn boxed(
|
||||
span: Span,
|
||||
id: StringLiteral<'a>,
|
||||
body: Option<ArenaBox<'a, TSModuleBlock<'a>>>,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> ArenaBox<'a, Self> {
|
||||
let builder = builder.builder();
|
||||
ArenaBox::new_in(Self::new(span, id, body, declare, builder), &builder.allocator())
|
||||
}
|
||||
|
||||
/// Build a [`TSExternalModuleDeclaration`] with `scope_id`.
|
||||
///
|
||||
/// If you want the built node to be allocated in the memory arena,
|
||||
/// use [`TSExternalModuleDeclaration::boxed_with_scope_id`] instead.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn new_with_scope_id(
|
||||
span: Span,
|
||||
id: StringLiteral<'a>,
|
||||
body: Option<ArenaBox<'a, TSModuleBlock<'a>>>,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
let builder = builder.builder();
|
||||
TSExternalModuleDeclaration {
|
||||
node_id: Cell::new(builder.node_id()),
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
declare,
|
||||
scope_id: Cell::new(Some(scope_id)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a [`TSExternalModuleDeclaration`] with `scope_id`, and store it in the memory arena.
|
||||
///
|
||||
/// Returns a [`Box`](ArenaBox) containing the newly-allocated node.
|
||||
/// If you want a stack-allocated node, use [`TSExternalModuleDeclaration::new_with_scope_id`] instead.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn boxed_with_scope_id(
|
||||
span: Span,
|
||||
id: StringLiteral<'a>,
|
||||
body: Option<ArenaBox<'a, TSModuleBlock<'a>>>,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> ArenaBox<'a, Self> {
|
||||
let builder = builder.builder();
|
||||
ArenaBox::new_in(
|
||||
Self::new_with_scope_id(span, id, body, declare, scope_id, builder),
|
||||
&builder.allocator(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TSNamespaceDeclaration<'a> {
|
||||
/// Build a [`TSNamespaceDeclaration`].
|
||||
///
|
||||
/// If you want the built node to be allocated in the memory arena,
|
||||
/// use [`TSNamespaceDeclaration::boxed`] instead.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn new(
|
||||
span: Span,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
let builder = builder.builder();
|
||||
TSNamespaceDeclaration {
|
||||
node_id: Cell::new(builder.node_id()),
|
||||
span,
|
||||
id,
|
||||
@@ -25406,23 +25627,23 @@ impl<'a> TSModuleDeclaration<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a [`TSModuleDeclaration`], and store it in the memory arena.
|
||||
/// Build a [`TSNamespaceDeclaration`], and store it in the memory arena.
|
||||
///
|
||||
/// Returns a [`Box`](ArenaBox) containing the newly-allocated node.
|
||||
/// If you want a stack-allocated node, use [`TSModuleDeclaration::new`] instead.
|
||||
/// If you want a stack-allocated node, use [`TSNamespaceDeclaration::new`] instead.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn boxed(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> ArenaBox<'a, Self> {
|
||||
@@ -25430,30 +25651,30 @@ impl<'a> TSModuleDeclaration<'a> {
|
||||
ArenaBox::new_in(Self::new(span, id, body, kind, declare, builder), &builder.allocator())
|
||||
}
|
||||
|
||||
/// Build a [`TSModuleDeclaration`] with `scope_id`.
|
||||
/// Build a [`TSNamespaceDeclaration`] with `scope_id`.
|
||||
///
|
||||
/// If you want the built node to be allocated in the memory arena,
|
||||
/// use [`TSModuleDeclaration::boxed_with_scope_id`] instead.
|
||||
/// use [`TSNamespaceDeclaration::boxed_with_scope_id`] instead.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn new_with_scope_id(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
let builder = builder.builder();
|
||||
TSModuleDeclaration {
|
||||
TSNamespaceDeclaration {
|
||||
node_id: Cell::new(builder.node_id()),
|
||||
span,
|
||||
id,
|
||||
@@ -25464,24 +25685,24 @@ impl<'a> TSModuleDeclaration<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a [`TSModuleDeclaration`] with `scope_id`, and store it in the memory arena.
|
||||
/// Build a [`TSNamespaceDeclaration`] with `scope_id`, and store it in the memory arena.
|
||||
///
|
||||
/// Returns a [`Box`](ArenaBox) containing the newly-allocated node.
|
||||
/// If you want a stack-allocated node, use [`TSModuleDeclaration::new_with_scope_id`] instead.
|
||||
/// If you want a stack-allocated node, use [`TSNamespaceDeclaration::new_with_scope_id`] instead.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn boxed_with_scope_id(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
@@ -25494,104 +25715,27 @@ impl<'a> TSModuleDeclaration<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TSModuleDeclarationName<'a> {
|
||||
/// Build a [`TSModuleDeclarationName::Identifier`].
|
||||
impl<'a> TSNamespaceDeclarationBody<'a> {
|
||||
/// Build a [`TSNamespaceDeclarationBody::TSNamespaceDeclaration`].
|
||||
///
|
||||
/// This node contains a [`TSNamespaceDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `name`: The identifier name being bound.
|
||||
#[inline]
|
||||
pub fn new_identifier(
|
||||
span: Span,
|
||||
name: impl Into<Ident<'a>>,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::Identifier(BindingIdentifier::new(span, name, builder.builder()))
|
||||
}
|
||||
|
||||
/// Build a [`TSModuleDeclarationName::Identifier`] with `symbol_id`.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `name`: The identifier name being bound.
|
||||
/// * `symbol_id`: Unique identifier for this binding.
|
||||
#[inline]
|
||||
pub fn new_identifier_with_symbol_id(
|
||||
span: Span,
|
||||
name: impl Into<Ident<'a>>,
|
||||
symbol_id: SymbolId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::Identifier(BindingIdentifier::new_with_symbol_id(
|
||||
span,
|
||||
name,
|
||||
symbol_id,
|
||||
builder.builder(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`TSModuleDeclarationName::StringLiteral`].
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: Node location in source code.
|
||||
/// * `value`: The value of the string.
|
||||
/// * `raw`: The raw string as it appears in source code.
|
||||
#[inline]
|
||||
pub fn new_string_literal(
|
||||
span: Span,
|
||||
value: impl Into<Str<'a>>,
|
||||
raw: Option<Str<'a>>,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::StringLiteral(StringLiteral::new(span, value, raw, builder.builder()))
|
||||
}
|
||||
|
||||
/// Build a [`TSModuleDeclarationName::StringLiteral`] with `lone_surrogates`.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: Node location in source code.
|
||||
/// * `value`: The value of the string.
|
||||
/// * `raw`: The raw string as it appears in source code.
|
||||
/// * `lone_surrogates`: The string value contains lone surrogates.
|
||||
#[inline]
|
||||
pub fn new_string_literal_with_lone_surrogates(
|
||||
span: Span,
|
||||
value: impl Into<Str<'a>>,
|
||||
raw: Option<Str<'a>>,
|
||||
lone_surrogates: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::StringLiteral(StringLiteral::new_with_lone_surrogates(
|
||||
span,
|
||||
value,
|
||||
raw,
|
||||
lone_surrogates,
|
||||
builder.builder(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TSModuleDeclarationBody<'a> {
|
||||
/// Build a [`TSModuleDeclarationBody::TSModuleDeclaration`].
|
||||
///
|
||||
/// This node contains a [`TSModuleDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
#[inline]
|
||||
pub fn new_ts_module_declaration(
|
||||
pub fn new_ts_namespace_declaration(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSModuleDeclaration(TSModuleDeclaration::boxed(
|
||||
Self::TSNamespaceDeclaration(TSNamespaceDeclaration::boxed(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
@@ -25601,28 +25745,28 @@ impl<'a> TSModuleDeclarationBody<'a> {
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`TSModuleDeclarationBody::TSModuleDeclaration`] with `scope_id`.
|
||||
/// Build a [`TSNamespaceDeclarationBody::TSNamespaceDeclaration`] with `scope_id`.
|
||||
///
|
||||
/// This node contains a [`TSModuleDeclaration`] that will be stored in the memory arena.
|
||||
/// This node contains a [`TSNamespaceDeclaration`] that will be stored in the memory arena.
|
||||
///
|
||||
/// ## Parameters
|
||||
/// * `span`: The [`Span`] covering this node
|
||||
/// * `id`: The name of the module/namespace being declared.
|
||||
/// * `id`
|
||||
/// * `body`
|
||||
/// * `kind`: The keyword used to define this module declaration.
|
||||
/// * `kind`
|
||||
/// * `declare`
|
||||
/// * `scope_id`
|
||||
#[inline]
|
||||
pub fn new_ts_module_declaration_with_scope_id(
|
||||
pub fn new_ts_namespace_declaration_with_scope_id(
|
||||
span: Span,
|
||||
id: TSModuleDeclarationName<'a>,
|
||||
body: Option<TSModuleDeclarationBody<'a>>,
|
||||
kind: TSModuleDeclarationKind,
|
||||
id: BindingIdentifier<'a>,
|
||||
body: TSNamespaceDeclarationBody<'a>,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
declare: bool,
|
||||
scope_id: ScopeId,
|
||||
builder: &impl GetAstBuilder<'a>,
|
||||
) -> Self {
|
||||
Self::TSModuleDeclaration(TSModuleDeclaration::boxed_with_scope_id(
|
||||
Self::TSNamespaceDeclaration(TSNamespaceDeclaration::boxed_with_scope_id(
|
||||
span,
|
||||
id,
|
||||
body,
|
||||
@@ -25633,7 +25777,7 @@ impl<'a> TSModuleDeclarationBody<'a> {
|
||||
))
|
||||
}
|
||||
|
||||
/// Build a [`TSModuleDeclarationBody::TSModuleBlock`].
|
||||
/// Build a [`TSNamespaceDeclarationBody::TSModuleBlock`].
|
||||
///
|
||||
/// This node contains a [`TSModuleBlock`] that will be stored in the memory arena.
|
||||
///
|
||||
|
||||
@@ -8,7 +8,7 @@ use oxc_syntax::node::NodeId;
|
||||
use crate::ast::*;
|
||||
|
||||
/// The largest integer value that can be mapped to an `AstType`/`AstKind` enum variant.
|
||||
pub const AST_TYPE_MAX: u8 = 190;
|
||||
pub const AST_TYPE_MAX: u8 = 191;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[repr(u8)]
|
||||
@@ -179,31 +179,32 @@ pub enum AstType {
|
||||
TSIndexSignatureName = 163,
|
||||
TSInterfaceHeritage = 164,
|
||||
TSTypePredicate = 165,
|
||||
TSModuleDeclaration = 166,
|
||||
TSGlobalDeclaration = 167,
|
||||
TSModuleBlock = 168,
|
||||
TSTypeLiteral = 169,
|
||||
TSInferType = 170,
|
||||
TSTypeQuery = 171,
|
||||
TSImportType = 172,
|
||||
TSImportTypeQualifiedName = 173,
|
||||
TSFunctionType = 174,
|
||||
TSConstructorType = 175,
|
||||
TSMappedType = 176,
|
||||
TSTemplateLiteralType = 177,
|
||||
TSAsExpression = 178,
|
||||
TSSatisfiesExpression = 179,
|
||||
TSTypeAssertion = 180,
|
||||
TSImportEqualsDeclaration = 181,
|
||||
TSExternalModuleReference = 182,
|
||||
TSNonNullExpression = 183,
|
||||
Decorator = 184,
|
||||
TSExportAssignment = 185,
|
||||
TSNamespaceExportDeclaration = 186,
|
||||
TSInstantiationExpression = 187,
|
||||
JSDocNullableType = 188,
|
||||
JSDocNonNullableType = 189,
|
||||
JSDocUnknownType = 190,
|
||||
TSExternalModuleDeclaration = 166,
|
||||
TSNamespaceDeclaration = 167,
|
||||
TSGlobalDeclaration = 168,
|
||||
TSModuleBlock = 169,
|
||||
TSTypeLiteral = 170,
|
||||
TSInferType = 171,
|
||||
TSTypeQuery = 172,
|
||||
TSImportType = 173,
|
||||
TSImportTypeQualifiedName = 174,
|
||||
TSFunctionType = 175,
|
||||
TSConstructorType = 176,
|
||||
TSMappedType = 177,
|
||||
TSTemplateLiteralType = 178,
|
||||
TSAsExpression = 179,
|
||||
TSSatisfiesExpression = 180,
|
||||
TSTypeAssertion = 181,
|
||||
TSImportEqualsDeclaration = 182,
|
||||
TSExternalModuleReference = 183,
|
||||
TSNonNullExpression = 184,
|
||||
Decorator = 185,
|
||||
TSExportAssignment = 186,
|
||||
TSNamespaceExportDeclaration = 187,
|
||||
TSInstantiationExpression = 188,
|
||||
JSDocNullableType = 189,
|
||||
JSDocNonNullableType = 190,
|
||||
JSDocUnknownType = 191,
|
||||
}
|
||||
|
||||
/// Untyped AST Node Kind
|
||||
@@ -389,7 +390,9 @@ pub enum AstKind<'a> {
|
||||
TSIndexSignatureName(&'a TSIndexSignatureName<'a>) = AstType::TSIndexSignatureName as u8,
|
||||
TSInterfaceHeritage(&'a TSInterfaceHeritage<'a>) = AstType::TSInterfaceHeritage as u8,
|
||||
TSTypePredicate(&'a TSTypePredicate<'a>) = AstType::TSTypePredicate as u8,
|
||||
TSModuleDeclaration(&'a TSModuleDeclaration<'a>) = AstType::TSModuleDeclaration as u8,
|
||||
TSExternalModuleDeclaration(&'a TSExternalModuleDeclaration<'a>) =
|
||||
AstType::TSExternalModuleDeclaration as u8,
|
||||
TSNamespaceDeclaration(&'a TSNamespaceDeclaration<'a>) = AstType::TSNamespaceDeclaration as u8,
|
||||
TSGlobalDeclaration(&'a TSGlobalDeclaration<'a>) = AstType::TSGlobalDeclaration as u8,
|
||||
TSModuleBlock(&'a TSModuleBlock<'a>) = AstType::TSModuleBlock as u8,
|
||||
TSTypeLiteral(&'a TSTypeLiteral<'a>) = AstType::TSTypeLiteral as u8,
|
||||
@@ -593,7 +596,8 @@ impl AstKind<'_> {
|
||||
Self::TSIndexSignatureName(it) => it.node_id(),
|
||||
Self::TSInterfaceHeritage(it) => it.node_id(),
|
||||
Self::TSTypePredicate(it) => it.node_id(),
|
||||
Self::TSModuleDeclaration(it) => it.node_id(),
|
||||
Self::TSExternalModuleDeclaration(it) => it.node_id(),
|
||||
Self::TSNamespaceDeclaration(it) => it.node_id(),
|
||||
Self::TSGlobalDeclaration(it) => it.node_id(),
|
||||
Self::TSModuleBlock(it) => it.node_id(),
|
||||
Self::TSTypeLiteral(it) => it.node_id(),
|
||||
@@ -792,7 +796,8 @@ impl AstKind<'_> {
|
||||
Self::TSIndexSignatureName(it) => it.set_node_id(node_id),
|
||||
Self::TSInterfaceHeritage(it) => it.set_node_id(node_id),
|
||||
Self::TSTypePredicate(it) => it.set_node_id(node_id),
|
||||
Self::TSModuleDeclaration(it) => it.set_node_id(node_id),
|
||||
Self::TSExternalModuleDeclaration(it) => it.set_node_id(node_id),
|
||||
Self::TSNamespaceDeclaration(it) => it.set_node_id(node_id),
|
||||
Self::TSGlobalDeclaration(it) => it.set_node_id(node_id),
|
||||
Self::TSModuleBlock(it) => it.set_node_id(node_id),
|
||||
Self::TSTypeLiteral(it) => it.set_node_id(node_id),
|
||||
@@ -993,7 +998,8 @@ impl GetSpan for AstKind<'_> {
|
||||
Self::TSIndexSignatureName(it) => it.span(),
|
||||
Self::TSInterfaceHeritage(it) => it.span(),
|
||||
Self::TSTypePredicate(it) => it.span(),
|
||||
Self::TSModuleDeclaration(it) => it.span(),
|
||||
Self::TSExternalModuleDeclaration(it) => it.span(),
|
||||
Self::TSNamespaceDeclaration(it) => it.span(),
|
||||
Self::TSGlobalDeclaration(it) => it.span(),
|
||||
Self::TSModuleBlock(it) => it.span(),
|
||||
Self::TSTypeLiteral(it) => it.span(),
|
||||
@@ -1195,7 +1201,8 @@ impl GetAddress for AstKind<'_> {
|
||||
Self::TSIndexSignatureName(it) => it.unstable_address(),
|
||||
Self::TSInterfaceHeritage(it) => it.unstable_address(),
|
||||
Self::TSTypePredicate(it) => it.unstable_address(),
|
||||
Self::TSModuleDeclaration(it) => it.unstable_address(),
|
||||
Self::TSExternalModuleDeclaration(it) => it.unstable_address(),
|
||||
Self::TSNamespaceDeclaration(it) => it.unstable_address(),
|
||||
Self::TSGlobalDeclaration(it) => it.unstable_address(),
|
||||
Self::TSModuleBlock(it) => it.unstable_address(),
|
||||
Self::TSTypeLiteral(it) => it.unstable_address(),
|
||||
@@ -2064,8 +2071,13 @@ impl<'a> AstKind<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_ts_module_declaration(self) -> Option<&'a TSModuleDeclaration<'a>> {
|
||||
if let Self::TSModuleDeclaration(v) = self { Some(v) } else { None }
|
||||
pub fn as_ts_external_module_declaration(self) -> Option<&'a TSExternalModuleDeclaration<'a>> {
|
||||
if let Self::TSExternalModuleDeclaration(v) = self { Some(v) } else { None }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_ts_namespace_declaration(self) -> Option<&'a TSNamespaceDeclaration<'a>> {
|
||||
if let Self::TSNamespaceDeclaration(v) = self { Some(v) } else { None }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -1404,7 +1404,8 @@ impl<'new_alloc> CloneIn<'new_alloc> for Statement<'_> {
|
||||
| Self::TSTypeAliasDeclaration(_)
|
||||
| Self::TSInterfaceDeclaration(_)
|
||||
| Self::TSEnumDeclaration(_)
|
||||
| Self::TSModuleDeclaration(_)
|
||||
| Self::TSExternalModuleDeclaration(_)
|
||||
| Self::TSNamespaceDeclaration(_)
|
||||
| Self::TSGlobalDeclaration(_)
|
||||
| Self::TSImportEqualsDeclaration(_) => Statement::from(CloneIn::clone_in_impl(
|
||||
self.to_declaration(),
|
||||
@@ -1511,7 +1512,10 @@ impl<'new_alloc> CloneIn<'new_alloc> for Declaration<'_> {
|
||||
with_semantic_ids,
|
||||
allocator,
|
||||
)),
|
||||
Self::TSModuleDeclaration(it) => Declaration::TSModuleDeclaration(
|
||||
Self::TSExternalModuleDeclaration(it) => Declaration::TSExternalModuleDeclaration(
|
||||
CloneIn::clone_in_impl(it, with_semantic_ids, allocator),
|
||||
),
|
||||
Self::TSNamespaceDeclaration(it) => Declaration::TSNamespaceDeclaration(
|
||||
CloneIn::clone_in_impl(it, with_semantic_ids, allocator),
|
||||
),
|
||||
Self::TSGlobalDeclaration(it) => Declaration::TSGlobalDeclaration(
|
||||
@@ -5076,15 +5080,37 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypePredicateName<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclaration<'_> {
|
||||
type Cloned = TSModuleDeclaration<'new_alloc>;
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for TSExternalModuleDeclaration<'_> {
|
||||
type Cloned = TSExternalModuleDeclaration<'new_alloc>;
|
||||
|
||||
fn clone_in_impl(
|
||||
&self,
|
||||
with_semantic_ids: CloneInSemanticIds,
|
||||
allocator: &'new_alloc Allocator,
|
||||
) -> Self::Cloned {
|
||||
TSModuleDeclaration {
|
||||
TSExternalModuleDeclaration {
|
||||
node_id: CloneIn::clone_in_impl(&self.node_id, with_semantic_ids, allocator),
|
||||
span: CloneIn::clone_in_impl(&self.span, with_semantic_ids, allocator),
|
||||
id: CloneIn::clone_in_impl(&self.id, with_semantic_ids, allocator),
|
||||
body: CloneIn::clone_in_impl(&self.body, with_semantic_ids, allocator),
|
||||
declare: CloneIn::clone_in_impl(&self.declare, with_semantic_ids, allocator),
|
||||
scope_id: oxc_syntax::semantic_id::SemanticId::clone_cell_option_id(
|
||||
&self.scope_id,
|
||||
with_semantic_ids,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for TSNamespaceDeclaration<'_> {
|
||||
type Cloned = TSNamespaceDeclaration<'new_alloc>;
|
||||
|
||||
fn clone_in_impl(
|
||||
&self,
|
||||
with_semantic_ids: CloneInSemanticIds,
|
||||
allocator: &'new_alloc Allocator,
|
||||
) -> Self::Cloned {
|
||||
TSNamespaceDeclaration {
|
||||
node_id: CloneIn::clone_in_impl(&self.node_id, with_semantic_ids, allocator),
|
||||
span: CloneIn::clone_in_impl(&self.span, with_semantic_ids, allocator),
|
||||
id: CloneIn::clone_in_impl(&self.id, with_semantic_ids, allocator),
|
||||
@@ -5099,8 +5125,8 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclaration<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclarationKind {
|
||||
type Cloned = TSModuleDeclarationKind;
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for TSNamespaceDeclarationKind {
|
||||
type Cloned = TSNamespaceDeclarationKind;
|
||||
|
||||
#[inline(always)]
|
||||
fn clone_in_impl(
|
||||
@@ -5112,8 +5138,8 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclarationKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclarationName<'_> {
|
||||
type Cloned = TSModuleDeclarationName<'new_alloc>;
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for TSNamespaceDeclarationBody<'_> {
|
||||
type Cloned = TSNamespaceDeclarationBody<'new_alloc>;
|
||||
|
||||
fn clone_in_impl(
|
||||
&self,
|
||||
@@ -5121,31 +5147,10 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclarationName<'_> {
|
||||
allocator: &'new_alloc Allocator,
|
||||
) -> Self::Cloned {
|
||||
match self {
|
||||
Self::Identifier(it) => TSModuleDeclarationName::Identifier(CloneIn::clone_in_impl(
|
||||
it,
|
||||
with_semantic_ids,
|
||||
allocator,
|
||||
)),
|
||||
Self::StringLiteral(it) => TSModuleDeclarationName::StringLiteral(
|
||||
Self::TSNamespaceDeclaration(it) => TSNamespaceDeclarationBody::TSNamespaceDeclaration(
|
||||
CloneIn::clone_in_impl(it, with_semantic_ids, allocator),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclarationBody<'_> {
|
||||
type Cloned = TSModuleDeclarationBody<'new_alloc>;
|
||||
|
||||
fn clone_in_impl(
|
||||
&self,
|
||||
with_semantic_ids: CloneInSemanticIds,
|
||||
allocator: &'new_alloc Allocator,
|
||||
) -> Self::Cloned {
|
||||
match self {
|
||||
Self::TSModuleDeclaration(it) => TSModuleDeclarationBody::TSModuleDeclaration(
|
||||
CloneIn::clone_in_impl(it, with_semantic_ids, allocator),
|
||||
),
|
||||
Self::TSModuleBlock(it) => TSModuleDeclarationBody::TSModuleBlock(
|
||||
Self::TSModuleBlock(it) => TSNamespaceDeclarationBody::TSModuleBlock(
|
||||
CloneIn::clone_in_impl(it, with_semantic_ids, allocator),
|
||||
),
|
||||
}
|
||||
|
||||
@@ -697,7 +697,10 @@ impl ContentEq for Statement<'_> {
|
||||
(Self::TSTypeAliasDeclaration(a), Self::TSTypeAliasDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSInterfaceDeclaration(a), Self::TSInterfaceDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSEnumDeclaration(a), Self::TSEnumDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSModuleDeclaration(a), Self::TSModuleDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSExternalModuleDeclaration(a), Self::TSExternalModuleDeclaration(b)) => {
|
||||
a.content_eq(b)
|
||||
}
|
||||
(Self::TSNamespaceDeclaration(a), Self::TSNamespaceDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSGlobalDeclaration(a), Self::TSGlobalDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSImportEqualsDeclaration(a), Self::TSImportEqualsDeclaration(b)) => {
|
||||
a.content_eq(b)
|
||||
@@ -747,7 +750,10 @@ impl ContentEq for Declaration<'_> {
|
||||
(Self::TSTypeAliasDeclaration(a), Self::TSTypeAliasDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSInterfaceDeclaration(a), Self::TSInterfaceDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSEnumDeclaration(a), Self::TSEnumDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSModuleDeclaration(a), Self::TSModuleDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSExternalModuleDeclaration(a), Self::TSExternalModuleDeclaration(b)) => {
|
||||
a.content_eq(b)
|
||||
}
|
||||
(Self::TSNamespaceDeclaration(a), Self::TSNamespaceDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSGlobalDeclaration(a), Self::TSGlobalDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSImportEqualsDeclaration(a), Self::TSImportEqualsDeclaration(b)) => {
|
||||
a.content_eq(b)
|
||||
@@ -2338,7 +2344,15 @@ impl ContentEq for TSTypePredicateName<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentEq for TSModuleDeclaration<'_> {
|
||||
impl ContentEq for TSExternalModuleDeclaration<'_> {
|
||||
fn content_eq(&self, other: &Self) -> bool {
|
||||
ContentEq::content_eq(&self.id, &other.id)
|
||||
&& ContentEq::content_eq(&self.body, &other.body)
|
||||
&& ContentEq::content_eq(&self.declare, &other.declare)
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentEq for TSNamespaceDeclaration<'_> {
|
||||
fn content_eq(&self, other: &Self) -> bool {
|
||||
ContentEq::content_eq(&self.id, &other.id)
|
||||
&& ContentEq::content_eq(&self.body, &other.body)
|
||||
@@ -2347,26 +2361,16 @@ impl ContentEq for TSModuleDeclaration<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentEq for TSModuleDeclarationKind {
|
||||
impl ContentEq for TSNamespaceDeclarationKind {
|
||||
fn content_eq(&self, other: &Self) -> bool {
|
||||
self == other
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentEq for TSModuleDeclarationName<'_> {
|
||||
impl ContentEq for TSNamespaceDeclarationBody<'_> {
|
||||
fn content_eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Self::Identifier(a), Self::Identifier(b)) => a.content_eq(b),
|
||||
(Self::StringLiteral(a), Self::StringLiteral(b)) => a.content_eq(b),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentEq for TSModuleDeclarationBody<'_> {
|
||||
fn content_eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Self::TSModuleDeclaration(a), Self::TSModuleDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSNamespaceDeclaration(a), Self::TSNamespaceDeclaration(b)) => a.content_eq(b),
|
||||
(Self::TSModuleBlock(a), Self::TSModuleBlock(b)) => a.content_eq(b),
|
||||
_ => false,
|
||||
}
|
||||
|
||||
@@ -2835,10 +2835,26 @@ impl<'a> Dummy<'a> for TSTypePredicateName<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Dummy<'a> for TSModuleDeclaration<'a> {
|
||||
/// Create a dummy [`TSModuleDeclaration`].
|
||||
impl<'a> Dummy<'a> for TSExternalModuleDeclaration<'a> {
|
||||
/// Create a dummy [`TSExternalModuleDeclaration`].
|
||||
///
|
||||
/// Does not allocate any data into arena.
|
||||
fn dummy(allocator: &'a Allocator) -> Self {
|
||||
Self {
|
||||
node_id: Dummy::dummy(allocator),
|
||||
span: Dummy::dummy(allocator),
|
||||
id: Dummy::dummy(allocator),
|
||||
body: Dummy::dummy(allocator),
|
||||
declare: Dummy::dummy(allocator),
|
||||
scope_id: Dummy::dummy(allocator),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Dummy<'a> for TSNamespaceDeclaration<'a> {
|
||||
/// Create a dummy [`TSNamespaceDeclaration`].
|
||||
///
|
||||
/// Has cost of making 1 allocation (64 bytes).
|
||||
fn dummy(allocator: &'a Allocator) -> Self {
|
||||
Self {
|
||||
node_id: Dummy::dummy(allocator),
|
||||
@@ -2852,8 +2868,8 @@ impl<'a> Dummy<'a> for TSModuleDeclaration<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Dummy<'a> for TSModuleDeclarationKind {
|
||||
/// Create a dummy [`TSModuleDeclarationKind`].
|
||||
impl<'a> Dummy<'a> for TSNamespaceDeclarationKind {
|
||||
/// Create a dummy [`TSNamespaceDeclarationKind`].
|
||||
///
|
||||
/// Does not allocate any data into arena.
|
||||
#[inline(always)]
|
||||
@@ -2862,17 +2878,8 @@ impl<'a> Dummy<'a> for TSModuleDeclarationKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Dummy<'a> for TSModuleDeclarationName<'a> {
|
||||
/// Create a dummy [`TSModuleDeclarationName`].
|
||||
///
|
||||
/// Does not allocate any data into arena.
|
||||
fn dummy(allocator: &'a Allocator) -> Self {
|
||||
Self::Identifier(Dummy::dummy(allocator))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Dummy<'a> for TSModuleDeclarationBody<'a> {
|
||||
/// Create a dummy [`TSModuleDeclarationBody`].
|
||||
impl<'a> Dummy<'a> for TSNamespaceDeclarationBody<'a> {
|
||||
/// Create a dummy [`TSNamespaceDeclarationBody`].
|
||||
///
|
||||
/// Has cost of making 1 allocation (64 bytes).
|
||||
fn dummy(allocator: &'a Allocator) -> Self {
|
||||
|
||||
@@ -825,7 +825,8 @@ impl ESTree for Statement<'_> {
|
||||
| Self::TSTypeAliasDeclaration(_)
|
||||
| Self::TSInterfaceDeclaration(_)
|
||||
| Self::TSEnumDeclaration(_)
|
||||
| Self::TSModuleDeclaration(_)
|
||||
| Self::TSExternalModuleDeclaration(_)
|
||||
| Self::TSNamespaceDeclaration(_)
|
||||
| Self::TSGlobalDeclaration(_)
|
||||
| Self::TSImportEqualsDeclaration(_) => self.to_declaration().serialize(serializer),
|
||||
Self::ImportDeclaration(_)
|
||||
@@ -882,7 +883,8 @@ impl ESTree for Declaration<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSInterfaceDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSEnumDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSModuleDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSExternalModuleDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSNamespaceDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSGlobalDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSImportEqualsDeclaration(it) => it.serialize(serializer),
|
||||
}
|
||||
@@ -2999,13 +3001,19 @@ impl ESTree for TSTypePredicateName<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ESTree for TSModuleDeclaration<'_> {
|
||||
impl ESTree for TSExternalModuleDeclaration<'_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
crate::serialize::ts::TSModuleDeclarationConverter(self).serialize(serializer)
|
||||
crate::serialize::ts::TSExternalModuleDeclarationConverter(self).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl ESTree for TSModuleDeclarationKind {
|
||||
impl ESTree for TSNamespaceDeclaration<'_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
crate::serialize::ts::TSNamespaceDeclarationConverter(self).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl ESTree for TSNamespaceDeclarationKind {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
match self {
|
||||
Self::Module => JsonSafeString("module").serialize(serializer),
|
||||
@@ -3014,19 +3022,10 @@ impl ESTree for TSModuleDeclarationKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl ESTree for TSModuleDeclarationName<'_> {
|
||||
impl ESTree for TSNamespaceDeclarationBody<'_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
match self {
|
||||
Self::Identifier(it) => it.serialize(serializer),
|
||||
Self::StringLiteral(it) => it.serialize(serializer),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ESTree for TSModuleDeclarationBody<'_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
match self {
|
||||
Self::TSModuleDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSNamespaceDeclaration(it) => it.serialize(serializer),
|
||||
Self::TSModuleBlock(it) => it.serialize(serializer),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +315,8 @@ impl GetAddress for Statement<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSInterfaceDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSEnumDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSModuleDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSExternalModuleDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSNamespaceDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSGlobalDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSImportEqualsDeclaration(it) => GetAddress::address(it),
|
||||
Self::ImportDeclaration(it) => GetAddress::address(it),
|
||||
@@ -341,7 +342,8 @@ impl GetAddress for Declaration<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSInterfaceDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSEnumDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSModuleDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSExternalModuleDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSNamespaceDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSGlobalDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSImportEqualsDeclaration(it) => GetAddress::address(it),
|
||||
}
|
||||
@@ -811,12 +813,12 @@ impl GetAddress for TSSignature<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GetAddress for TSModuleDeclarationBody<'_> {
|
||||
impl GetAddress for TSNamespaceDeclarationBody<'_> {
|
||||
// `#[inline]` because compiler should boil this down to a single assembly instruction
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
match self {
|
||||
Self::TSModuleDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSNamespaceDeclaration(it) => GetAddress::address(it),
|
||||
Self::TSModuleBlock(it) => GetAddress::address(it),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,7 +619,8 @@ impl GetSpan for Statement<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSInterfaceDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSEnumDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSModuleDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSExternalModuleDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSNamespaceDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSGlobalDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSImportEqualsDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::ImportDeclaration(it) => GetSpan::span(&**it),
|
||||
@@ -664,7 +665,8 @@ impl GetSpan for Declaration<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSInterfaceDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSEnumDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSModuleDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSExternalModuleDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSNamespaceDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSGlobalDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSImportEqualsDeclaration(it) => GetSpan::span(&**it),
|
||||
}
|
||||
@@ -2042,26 +2044,24 @@ impl GetSpan for TSTypePredicateName<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GetSpan for TSModuleDeclaration<'_> {
|
||||
impl GetSpan for TSExternalModuleDeclaration<'_> {
|
||||
#[inline]
|
||||
fn span(&self) -> Span {
|
||||
self.span
|
||||
}
|
||||
}
|
||||
|
||||
impl GetSpan for TSModuleDeclarationName<'_> {
|
||||
impl GetSpan for TSNamespaceDeclaration<'_> {
|
||||
#[inline]
|
||||
fn span(&self) -> Span {
|
||||
match self {
|
||||
Self::Identifier(it) => GetSpan::span(it),
|
||||
Self::StringLiteral(it) => GetSpan::span(it),
|
||||
}
|
||||
self.span
|
||||
}
|
||||
}
|
||||
|
||||
impl GetSpan for TSModuleDeclarationBody<'_> {
|
||||
impl GetSpan for TSNamespaceDeclarationBody<'_> {
|
||||
fn span(&self) -> Span {
|
||||
match self {
|
||||
Self::TSModuleDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSNamespaceDeclaration(it) => GetSpan::span(&**it),
|
||||
Self::TSModuleBlock(it) => GetSpan::span(&**it),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,7 +618,8 @@ impl GetSpanMut for Statement<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSInterfaceDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSEnumDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSModuleDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSExternalModuleDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSNamespaceDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSGlobalDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSImportEqualsDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::ImportDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
@@ -663,7 +664,8 @@ impl GetSpanMut for Declaration<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSInterfaceDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSEnumDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSModuleDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSExternalModuleDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSNamespaceDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSGlobalDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSImportEqualsDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
}
|
||||
@@ -2041,26 +2043,24 @@ impl GetSpanMut for TSTypePredicateName<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GetSpanMut for TSModuleDeclaration<'_> {
|
||||
impl GetSpanMut for TSExternalModuleDeclaration<'_> {
|
||||
#[inline]
|
||||
fn span_mut(&mut self) -> &mut Span {
|
||||
&mut self.span
|
||||
}
|
||||
}
|
||||
|
||||
impl GetSpanMut for TSModuleDeclarationName<'_> {
|
||||
impl GetSpanMut for TSNamespaceDeclaration<'_> {
|
||||
#[inline]
|
||||
fn span_mut(&mut self) -> &mut Span {
|
||||
match self {
|
||||
Self::Identifier(it) => GetSpanMut::span_mut(it),
|
||||
Self::StringLiteral(it) => GetSpanMut::span_mut(it),
|
||||
}
|
||||
&mut self.span
|
||||
}
|
||||
}
|
||||
|
||||
impl GetSpanMut for TSModuleDeclarationBody<'_> {
|
||||
impl GetSpanMut for TSNamespaceDeclarationBody<'_> {
|
||||
fn span_mut(&mut self) -> &mut Span {
|
||||
match self {
|
||||
Self::TSModuleDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSNamespaceDeclaration(it) => GetSpanMut::span_mut(&mut **it),
|
||||
Self::TSModuleBlock(it) => GetSpanMut::span_mut(&mut **it),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,11 +422,11 @@ impl<'a> ReplaceWith<'a> for TSTypePredicate<'a> {}
|
||||
|
||||
impl<'a> ReplaceWith<'a> for TSTypePredicateName<'a> {}
|
||||
|
||||
impl<'a> ReplaceWith<'a> for TSModuleDeclaration<'a> {}
|
||||
impl<'a> ReplaceWith<'a> for TSExternalModuleDeclaration<'a> {}
|
||||
|
||||
impl<'a> ReplaceWith<'a> for TSModuleDeclarationName<'a> {}
|
||||
impl<'a> ReplaceWith<'a> for TSNamespaceDeclaration<'a> {}
|
||||
|
||||
impl<'a> ReplaceWith<'a> for TSModuleDeclarationBody<'a> {}
|
||||
impl<'a> ReplaceWith<'a> for TSNamespaceDeclarationBody<'a> {}
|
||||
|
||||
impl<'a> ReplaceWith<'a> for TSGlobalDeclaration<'a> {}
|
||||
|
||||
|
||||
@@ -424,11 +424,11 @@ impl<'a> TakeIn<'a> for TSTypePredicate<'a> {}
|
||||
|
||||
impl<'a> TakeIn<'a> for TSTypePredicateName<'a> {}
|
||||
|
||||
impl<'a> TakeIn<'a> for TSModuleDeclaration<'a> {}
|
||||
impl<'a> TakeIn<'a> for TSExternalModuleDeclaration<'a> {}
|
||||
|
||||
impl<'a> TakeIn<'a> for TSModuleDeclarationName<'a> {}
|
||||
impl<'a> TakeIn<'a> for TSNamespaceDeclaration<'a> {}
|
||||
|
||||
impl<'a> TakeIn<'a> for TSModuleDeclarationBody<'a> {}
|
||||
impl<'a> TakeIn<'a> for TSNamespaceDeclarationBody<'a> {}
|
||||
|
||||
impl<'a> TakeIn<'a> for TSGlobalDeclaration<'a> {}
|
||||
|
||||
|
||||
@@ -340,7 +340,9 @@ impl UnstableAddress for TSInterfaceHeritage<'_> {}
|
||||
|
||||
impl UnstableAddress for TSTypePredicate<'_> {}
|
||||
|
||||
impl UnstableAddress for TSModuleDeclaration<'_> {}
|
||||
impl UnstableAddress for TSExternalModuleDeclaration<'_> {}
|
||||
|
||||
impl UnstableAddress for TSNamespaceDeclaration<'_> {}
|
||||
|
||||
impl UnstableAddress for TSGlobalDeclaration<'_> {}
|
||||
|
||||
|
||||
@@ -3020,8 +3020,8 @@ impl TSTypePredicate<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl TSModuleDeclaration<'_> {
|
||||
/// Get [`NodeId`] of [`TSModuleDeclaration`].
|
||||
impl TSExternalModuleDeclaration<'_> {
|
||||
/// Get [`NodeId`] of [`TSExternalModuleDeclaration`].
|
||||
///
|
||||
/// Only use this method on a post-semantic AST where [`NodeId`]s are always defined.
|
||||
#[inline]
|
||||
@@ -3029,13 +3029,13 @@ impl TSModuleDeclaration<'_> {
|
||||
self.node_id.get()
|
||||
}
|
||||
|
||||
/// Set [`NodeId`] of [`TSModuleDeclaration`].
|
||||
/// Set [`NodeId`] of [`TSExternalModuleDeclaration`].
|
||||
#[inline]
|
||||
pub fn set_node_id(&self, node_id: NodeId) {
|
||||
self.node_id.set(node_id);
|
||||
}
|
||||
|
||||
/// Get [`ScopeId`] of [`TSModuleDeclaration`].
|
||||
/// Get [`ScopeId`] of [`TSExternalModuleDeclaration`].
|
||||
///
|
||||
/// Only use this method on a post-semantic AST where [`ScopeId`]s are always defined.
|
||||
///
|
||||
@@ -3046,7 +3046,40 @@ impl TSModuleDeclaration<'_> {
|
||||
self.scope_id.get().unwrap()
|
||||
}
|
||||
|
||||
/// Set [`ScopeId`] of [`TSModuleDeclaration`].
|
||||
/// Set [`ScopeId`] of [`TSExternalModuleDeclaration`].
|
||||
#[inline]
|
||||
pub fn set_scope_id(&self, scope_id: ScopeId) {
|
||||
self.scope_id.set(Some(scope_id));
|
||||
}
|
||||
}
|
||||
|
||||
impl TSNamespaceDeclaration<'_> {
|
||||
/// Get [`NodeId`] of [`TSNamespaceDeclaration`].
|
||||
///
|
||||
/// Only use this method on a post-semantic AST where [`NodeId`]s are always defined.
|
||||
#[inline]
|
||||
pub fn node_id(&self) -> NodeId {
|
||||
self.node_id.get()
|
||||
}
|
||||
|
||||
/// Set [`NodeId`] of [`TSNamespaceDeclaration`].
|
||||
#[inline]
|
||||
pub fn set_node_id(&self, node_id: NodeId) {
|
||||
self.node_id.set(node_id);
|
||||
}
|
||||
|
||||
/// Get [`ScopeId`] of [`TSNamespaceDeclaration`].
|
||||
///
|
||||
/// Only use this method on a post-semantic AST where [`ScopeId`]s are always defined.
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if `scope_id` is [`None`].
|
||||
#[inline]
|
||||
pub fn scope_id(&self) -> ScopeId {
|
||||
self.scope_id.get().unwrap()
|
||||
}
|
||||
|
||||
/// Set [`ScopeId`] of [`TSNamespaceDeclaration`].
|
||||
#[inline]
|
||||
pub fn set_scope_id(&self, scope_id: ScopeId) {
|
||||
self.scope_id.set(Some(scope_id));
|
||||
@@ -3879,7 +3912,8 @@ impl Statement<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => it.node_id(),
|
||||
Self::TSInterfaceDeclaration(it) => it.node_id(),
|
||||
Self::TSEnumDeclaration(it) => it.node_id(),
|
||||
Self::TSModuleDeclaration(it) => it.node_id(),
|
||||
Self::TSExternalModuleDeclaration(it) => it.node_id(),
|
||||
Self::TSNamespaceDeclaration(it) => it.node_id(),
|
||||
Self::TSGlobalDeclaration(it) => it.node_id(),
|
||||
Self::TSImportEqualsDeclaration(it) => it.node_id(),
|
||||
Self::ImportDeclaration(it) => it.node_id(),
|
||||
@@ -3906,7 +3940,8 @@ impl Declaration<'_> {
|
||||
Self::TSTypeAliasDeclaration(it) => it.node_id(),
|
||||
Self::TSInterfaceDeclaration(it) => it.node_id(),
|
||||
Self::TSEnumDeclaration(it) => it.node_id(),
|
||||
Self::TSModuleDeclaration(it) => it.node_id(),
|
||||
Self::TSExternalModuleDeclaration(it) => it.node_id(),
|
||||
Self::TSNamespaceDeclaration(it) => it.node_id(),
|
||||
Self::TSGlobalDeclaration(it) => it.node_id(),
|
||||
Self::TSImportEqualsDeclaration(it) => it.node_id(),
|
||||
}
|
||||
@@ -4488,25 +4523,13 @@ impl TSTypePredicateName<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl TSModuleDeclarationName<'_> {
|
||||
/// Get [`NodeId`] of [`TSModuleDeclarationName`].
|
||||
impl TSNamespaceDeclarationBody<'_> {
|
||||
/// Get [`NodeId`] of [`TSNamespaceDeclarationBody`].
|
||||
// `#[inline(always)]` because this should boil down to a single instruction.
|
||||
#[inline(always)]
|
||||
pub fn node_id(&self) -> NodeId {
|
||||
match self {
|
||||
Self::Identifier(it) => it.node_id(),
|
||||
Self::StringLiteral(it) => it.node_id(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TSModuleDeclarationBody<'_> {
|
||||
/// Get [`NodeId`] of [`TSModuleDeclarationBody`].
|
||||
// `#[inline(always)]` because this should boil down to a single instruction.
|
||||
#[inline(always)]
|
||||
pub fn node_id(&self) -> NodeId {
|
||||
match self {
|
||||
Self::TSModuleDeclaration(it) => it.node_id(),
|
||||
Self::TSNamespaceDeclaration(it) => it.node_id(),
|
||||
Self::TSModuleBlock(it) => it.node_id(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2626,7 +2626,8 @@ impl<'a> Statement<'a> {
|
||||
| Self::TSTypeAliasDeclaration(_)
|
||||
| Self::TSInterfaceDeclaration(_)
|
||||
| Self::TSEnumDeclaration(_)
|
||||
| Self::TSModuleDeclaration(_)
|
||||
| Self::TSExternalModuleDeclaration(_)
|
||||
| Self::TSNamespaceDeclaration(_)
|
||||
| Self::TSGlobalDeclaration(_)
|
||||
| Self::TSImportEqualsDeclaration(_)
|
||||
)
|
||||
@@ -2727,7 +2728,10 @@ impl<'a> TryFrom<Statement<'a>> for Declaration<'a> {
|
||||
Statement::TSTypeAliasDeclaration(o) => Ok(Declaration::TSTypeAliasDeclaration(o)),
|
||||
Statement::TSInterfaceDeclaration(o) => Ok(Declaration::TSInterfaceDeclaration(o)),
|
||||
Statement::TSEnumDeclaration(o) => Ok(Declaration::TSEnumDeclaration(o)),
|
||||
Statement::TSModuleDeclaration(o) => Ok(Declaration::TSModuleDeclaration(o)),
|
||||
Statement::TSExternalModuleDeclaration(o) => {
|
||||
Ok(Declaration::TSExternalModuleDeclaration(o))
|
||||
}
|
||||
Statement::TSNamespaceDeclaration(o) => Ok(Declaration::TSNamespaceDeclaration(o)),
|
||||
Statement::TSGlobalDeclaration(o) => Ok(Declaration::TSGlobalDeclaration(o)),
|
||||
Statement::TSImportEqualsDeclaration(o) => {
|
||||
Ok(Declaration::TSImportEqualsDeclaration(o))
|
||||
@@ -2750,7 +2754,10 @@ impl<'a> From<Declaration<'a>> for Statement<'a> {
|
||||
Declaration::TSTypeAliasDeclaration(o) => Statement::TSTypeAliasDeclaration(o),
|
||||
Declaration::TSInterfaceDeclaration(o) => Statement::TSInterfaceDeclaration(o),
|
||||
Declaration::TSEnumDeclaration(o) => Statement::TSEnumDeclaration(o),
|
||||
Declaration::TSModuleDeclaration(o) => Statement::TSModuleDeclaration(o),
|
||||
Declaration::TSExternalModuleDeclaration(o) => {
|
||||
Statement::TSExternalModuleDeclaration(o)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(o) => Statement::TSNamespaceDeclaration(o),
|
||||
Declaration::TSGlobalDeclaration(o) => Statement::TSGlobalDeclaration(o),
|
||||
Declaration::TSImportEqualsDeclaration(o) => Statement::TSImportEqualsDeclaration(o),
|
||||
}
|
||||
@@ -5604,7 +5611,8 @@ macro_rules! match_declaration {
|
||||
| $ty::TSTypeAliasDeclaration(_)
|
||||
| $ty::TSInterfaceDeclaration(_)
|
||||
| $ty::TSEnumDeclaration(_)
|
||||
| $ty::TSModuleDeclaration(_)
|
||||
| $ty::TSExternalModuleDeclaration(_)
|
||||
| $ty::TSNamespaceDeclaration(_)
|
||||
| $ty::TSGlobalDeclaration(_)
|
||||
| $ty::TSImportEqualsDeclaration(_)
|
||||
};
|
||||
|
||||
+144
-139
@@ -46,179 +46,184 @@ impl ESTree for ExpressionStatementDirective<'_, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converter for `TSModuleDeclaration`.
|
||||
///
|
||||
/// Our AST represents `module X.Y.Z {}` as 3 x nested `TSModuleDeclaration`s.
|
||||
/// TS-ESTree represents it as a single `TSModuleDeclaration`,
|
||||
/// with a nested tree of `TSQualifiedName`s as `id`.
|
||||
/// Converter for [`TSExternalModuleDeclaration`].
|
||||
#[ast_meta]
|
||||
#[estree(raw_deser = "
|
||||
const kind = DESER[TSModuleDeclarationKind](POS_OFFSET.kind),
|
||||
start = DESER[i32](POS_OFFSET.span.start),
|
||||
const start = DESER[i32](POS_OFFSET.span.start),
|
||||
end = DESER[i32](POS_OFFSET.span.end),
|
||||
declare = DESER[bool](POS_OFFSET.declare);
|
||||
|
||||
let node;
|
||||
const previousParent = parent;
|
||||
const body = DESER[Option<Box<TSModuleBlock>>](POS_OFFSET.body);
|
||||
const node = parent = {
|
||||
type: 'TSModuleDeclaration',
|
||||
id: null,
|
||||
...(body !== null && { body }),
|
||||
kind: 'module',
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
...(RANGE && { range: [start, end] }),
|
||||
...(PARENT && { parent }),
|
||||
};
|
||||
|
||||
let body = DESER[Option<TSModuleDeclarationBody>](POS_OFFSET.body);
|
||||
if (body === null) {
|
||||
node = parent = {
|
||||
type: 'TSModuleDeclaration',
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
...(RANGE && { range: [start, end] }),
|
||||
...(PARENT && { parent }),
|
||||
};
|
||||
node.id = DESER[TSModuleDeclarationName](POS_OFFSET.id);
|
||||
} else {
|
||||
node = parent = {
|
||||
type: 'TSModuleDeclaration',
|
||||
id: null,
|
||||
body,
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
...(RANGE && { range: [start, end] }),
|
||||
...(PARENT && { parent }),
|
||||
};
|
||||
|
||||
const id = DESER[TSModuleDeclarationName](POS_OFFSET.id);
|
||||
|
||||
if (body.type === 'TSModuleBlock') {
|
||||
node.id = id;
|
||||
if (PARENT) body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === 'Identifier') {
|
||||
let start, end;
|
||||
const outerId = node.id = parent = {
|
||||
type: 'TSQualifiedName',
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: start = id.start,
|
||||
end: end = innerId.end,
|
||||
...(RANGE && { range: [start, end] }),
|
||||
...(PARENT && { parent: node }),
|
||||
};
|
||||
if (PARENT) id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
if (PARENT) innerId.parent = node;
|
||||
|
||||
const { start } = id;
|
||||
while (true) {
|
||||
if (RANGE) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
} else {
|
||||
innerId.start = start;
|
||||
}
|
||||
if (innerId.left.type === 'Identifier') break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
|
||||
let end;
|
||||
const right = innerId.left;
|
||||
const left = innerId.left = {
|
||||
type: 'TSQualifiedName',
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: end = right.end,
|
||||
...(RANGE && { range: [start, end] }),
|
||||
...(PARENT && { parent: innerId }),
|
||||
};
|
||||
if (PARENT) id.parent = right.parent = left;
|
||||
}
|
||||
|
||||
if (Object.hasOwn(body, 'body')) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
if (PARENT) body.parent = node;
|
||||
} else {
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
node.id = DESER[StringLiteral](POS_OFFSET.id);
|
||||
if (body !== null) {
|
||||
if (PARENT) body.parent = node;
|
||||
}
|
||||
|
||||
if (PARENT) parent = previousParent;
|
||||
|
||||
node
|
||||
")]
|
||||
pub struct TSModuleDeclarationConverter<'a, 'b>(pub &'b TSModuleDeclaration<'a>);
|
||||
pub struct TSExternalModuleDeclarationConverter<'a, 'b>(pub &'b TSExternalModuleDeclaration<'a>);
|
||||
|
||||
impl ESTree for TSModuleDeclarationConverter<'_, '_> {
|
||||
impl ESTree for TSExternalModuleDeclarationConverter<'_, '_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
let module = self.0;
|
||||
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("TSModuleDeclaration"));
|
||||
state.serialize_field("id", &module.id);
|
||||
if let Some(body) = &module.body {
|
||||
state.serialize_field("body", body);
|
||||
}
|
||||
state.serialize_field("kind", &JsonSafeString("module"));
|
||||
state.serialize_field("declare", &module.declare);
|
||||
state.serialize_field("global", &false);
|
||||
state.serialize_span(module.span);
|
||||
state.end();
|
||||
}
|
||||
}
|
||||
|
||||
match &module.body {
|
||||
Some(TSModuleDeclarationBody::TSModuleDeclaration(inner_module)) => {
|
||||
// Nested modules e.g. `module X.Y.Z {}`.
|
||||
// Collect all IDs in a `Vec`, in order they appear (i.e. [`X`, `Y`, `Z`]).
|
||||
// Also get the inner `TSModuleBlock`.
|
||||
/// Converter for [`TSNamespaceDeclaration`].
|
||||
///
|
||||
/// Our AST represents `module X.Y.Z {}` as 3 x nested `TSNamespaceDeclaration`s.
|
||||
/// TS-ESTree represents it as a single `TSModuleDeclaration`, with a nested tree of
|
||||
/// `TSQualifiedName`s as `id`.
|
||||
#[ast_meta]
|
||||
#[estree(raw_deser = "
|
||||
const kind = DESER[TSNamespaceDeclarationKind](POS_OFFSET.kind),
|
||||
start = DESER[i32](POS_OFFSET.span.start),
|
||||
end = DESER[i32](POS_OFFSET.span.end),
|
||||
declare = DESER[bool](POS_OFFSET.declare);
|
||||
|
||||
const previousParent = parent;
|
||||
let body = DESER[TSNamespaceDeclarationBody](POS_OFFSET.body);
|
||||
const node = parent = {
|
||||
type: 'TSModuleDeclaration',
|
||||
id: null,
|
||||
body,
|
||||
kind,
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
...(RANGE && { range: [start, end] }),
|
||||
...(PARENT && { parent }),
|
||||
};
|
||||
|
||||
const id = DESER[BindingIdentifier](POS_OFFSET.id);
|
||||
if (body.type === 'TSModuleBlock') {
|
||||
node.id = id;
|
||||
if (PARENT) body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === 'Identifier') {
|
||||
let start, end;
|
||||
const outerId = node.id = parent = {
|
||||
type: 'TSQualifiedName',
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: start = id.start,
|
||||
end: end = innerId.end,
|
||||
...(RANGE && { range: [start, end] }),
|
||||
...(PARENT && { parent: node }),
|
||||
};
|
||||
if (PARENT) id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
if (PARENT) innerId.parent = node;
|
||||
|
||||
const { start } = id;
|
||||
while (true) {
|
||||
if (RANGE) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
} else {
|
||||
innerId.start = start;
|
||||
}
|
||||
if (innerId.left.type === 'Identifier') break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
|
||||
let end;
|
||||
const right = innerId.left;
|
||||
const left = innerId.left = {
|
||||
type: 'TSQualifiedName',
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: end = right.end,
|
||||
...(RANGE && { range: [start, end] }),
|
||||
...(PARENT && { parent: innerId }),
|
||||
};
|
||||
if (PARENT) id.parent = right.parent = left;
|
||||
}
|
||||
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
if (PARENT) body.parent = node;
|
||||
}
|
||||
|
||||
if (PARENT) parent = previousParent;
|
||||
|
||||
node
|
||||
")]
|
||||
pub struct TSNamespaceDeclarationConverter<'a, 'b>(pub &'b TSNamespaceDeclaration<'a>);
|
||||
|
||||
impl ESTree for TSNamespaceDeclarationConverter<'_, '_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) {
|
||||
let namespace = self.0;
|
||||
|
||||
let mut state = serializer.serialize_struct();
|
||||
state.serialize_field("type", &JsonSafeString("TSModuleDeclaration"));
|
||||
|
||||
match &namespace.body {
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(inner_namespace) => {
|
||||
// Nested namespaces e.g. `module X.Y.Z {}`. Collect all IDs in source order and
|
||||
// get the innermost `TSModuleBlock`.
|
||||
let mut parts = Vec::with_capacity(4);
|
||||
parts.push(&namespace.id);
|
||||
|
||||
let TSModuleDeclarationName::Identifier(id) = &module.id else { unreachable!() };
|
||||
parts.push(id);
|
||||
|
||||
let mut body = None;
|
||||
let mut inner_module = inner_module.as_ref();
|
||||
let mut body = &inner_namespace.body;
|
||||
parts.push(&inner_namespace.id);
|
||||
loop {
|
||||
let TSModuleDeclarationName::Identifier(id) = &inner_module.id else {
|
||||
unreachable!()
|
||||
};
|
||||
parts.push(id);
|
||||
|
||||
match &inner_module.body {
|
||||
Some(TSModuleDeclarationBody::TSModuleDeclaration(inner_inner_module)) => {
|
||||
inner_module = inner_inner_module.as_ref();
|
||||
match body {
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(inner_namespace) => {
|
||||
parts.push(&inner_namespace.id);
|
||||
body = &inner_namespace.body;
|
||||
}
|
||||
Some(TSModuleDeclarationBody::TSModuleBlock(block)) => {
|
||||
body = Some(block.as_ref());
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => {
|
||||
state.serialize_field("id", &TSModuleDeclarationIdParts(&parts));
|
||||
state.serialize_field("body", block);
|
||||
break;
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize `parts` as a nested tree of `TSQualifiedName`s
|
||||
state.serialize_field("id", &TSModuleDeclarationIdParts(&parts));
|
||||
|
||||
// Skip `body` field if it's `None`
|
||||
if let Some(body) = body {
|
||||
state.serialize_field("body", body);
|
||||
}
|
||||
}
|
||||
Some(TSModuleDeclarationBody::TSModuleBlock(block)) => {
|
||||
// No nested modules.
|
||||
// Serialize as usual, with `id` being either a `BindingIdentifier` or `StringLiteral`.
|
||||
state.serialize_field("id", &module.id);
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => {
|
||||
state.serialize_field("id", &namespace.id);
|
||||
state.serialize_field("body", block);
|
||||
}
|
||||
None => {
|
||||
// No body. Skip `body` field.
|
||||
state.serialize_field("id", &module.id);
|
||||
}
|
||||
}
|
||||
|
||||
state.serialize_field("kind", &module.kind);
|
||||
state.serialize_field("declare", &module.declare);
|
||||
state.serialize_field("kind", &namespace.kind);
|
||||
state.serialize_field("declare", &namespace.declare);
|
||||
state.serialize_field("global", &false);
|
||||
|
||||
state.serialize_span(module.span);
|
||||
|
||||
state.serialize_span(namespace.span);
|
||||
state.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,123 +8,122 @@ use crate::ast::{EnumDetails, EnumVariant, InheritedEnum};
|
||||
pub static ENUMS: phf::Map<&'static str, EnumDetails> = ::phf::Map {
|
||||
key: 16287231350648472473,
|
||||
disps: &[
|
||||
(0, 11),
|
||||
(0, 4),
|
||||
(0, 5),
|
||||
(0, 0),
|
||||
(0, 7),
|
||||
(0, 37),
|
||||
(0, 0),
|
||||
(0, 1),
|
||||
(0, 1),
|
||||
(0, 2),
|
||||
(1, 1),
|
||||
(0, 4),
|
||||
(0, 0),
|
||||
(0, 5),
|
||||
(0, 3),
|
||||
(0, 22),
|
||||
(0, 20),
|
||||
(0, 19),
|
||||
(0, 38),
|
||||
(0, 15),
|
||||
(0, 36),
|
||||
(0, 43),
|
||||
(1, 0),
|
||||
(0, 72),
|
||||
(0, 12),
|
||||
(0, 24),
|
||||
(1, 82),
|
||||
(0, 0),
|
||||
(0, 52),
|
||||
(1, 7),
|
||||
(1, 38),
|
||||
(0, 72),
|
||||
(0, 0),
|
||||
(0, 41),
|
||||
(0, 30),
|
||||
(1, 30),
|
||||
(0, 0),
|
||||
(0, 31),
|
||||
(0, 56),
|
||||
(0, 0),
|
||||
(7, 6),
|
||||
(1, 24),
|
||||
(6, 16),
|
||||
(0, 4),
|
||||
(0, 8),
|
||||
(0, 59),
|
||||
(0, 20),
|
||||
(1, 73),
|
||||
(1, 69),
|
||||
(0, 46),
|
||||
(0, 15),
|
||||
],
|
||||
entries: &[
|
||||
("ChainElement", EnumDetails { is_fieldless: false, inherits: &[1] }),
|
||||
("TSLiteral", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("FunctionType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSTupleElement", EnumDetails { is_fieldless: false, inherits: &[7] }),
|
||||
("ExportLocalName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("AssignmentTargetPattern", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSModuleDeclarationBody", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("LookAroundAssertionKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("UpdateOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("CommentKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("MethodDefinitionType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("Statement", EnumDetails { is_fieldless: false, inherits: &[5, 6] }),
|
||||
("TSEnumMemberName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("LanguageVariant", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("BigintBase", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("BindingPattern", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("CommentPosition", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSTypeName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("PropertyKey", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("FileExtension", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("JSXExpression", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("AssignmentTarget", EnumDetails { is_fieldless: false, inherits: &[3, 4] }),
|
||||
("LogicalOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("CharacterClassEscapeKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ModuleExportName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("Declaration", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ImportDeclarationSpecifier", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ExportImportName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("Expression", EnumDetails { is_fieldless: false, inherits: &[1] }),
|
||||
("JSXElementName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSModuleDeclarationName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("CharacterClassContentsKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ArrayExpressionElement", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("TSType", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSImportTypeQualifier", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ErrorSeverity", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("BinaryOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ImportAttributeKey", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSAccessibility", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("JSXAttributeName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("PropertyDefinitionType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("AssignmentOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ImportPhase", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSTypeQueryExprName", EnumDetails { is_fieldless: false, inherits: &[8] }),
|
||||
("JSXChild", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("JSXMemberExpressionObject", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ForStatementInit", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("MemberExpression", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("Term", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ImportOrExportKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("PropertyKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("MethodDefinitionKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ClassType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSMethodSignatureKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("AssignmentTargetProperty", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("FormalParameterKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ClassElement", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ModuleDeclaration", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("UpdateOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("JSXAttributeItem", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ImportImportName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("Argument", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("CharacterKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSTypePredicateName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSModuleDeclarationKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ExportDefaultDeclarationKind", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("TSTypeOperatorOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("Language", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("AccessorPropertyType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("BoundaryAssertionKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSMappedTypeModifierOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ObjectPropertyKind", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("CommentContent", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("SimpleAssignmentTarget", EnumDetails { is_fieldless: false, inherits: &[1] }),
|
||||
("ClassType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ErrorSeverity", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("WithClauseKeyword", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ExportExportName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("VariableDeclarationKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSModuleReference", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("NumberBase", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("AssignmentTargetMaybeDefault", EnumDetails { is_fieldless: false, inherits: &[2] }),
|
||||
("ArrowFunctionBody", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("ForStatementLeft", EnumDetails { is_fieldless: false, inherits: &[2] }),
|
||||
("Term", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("JSXElementName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("CharacterClassContentsKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ObjectPropertyKind", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("Language", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("Declaration", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ModuleKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("CharacterClassContents", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("JSXAttributeValue", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSSignature", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("FileExtension", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSEnumMemberName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("NumberBase", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("JSXAttributeName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ModuleExportName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSType", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("UnaryOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("VariableDeclarationKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSMappedTypeModifierOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ClassElement", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ChainElement", EnumDetails { is_fieldless: false, inherits: &[1] }),
|
||||
("CharacterClassEscapeKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("Expression", EnumDetails { is_fieldless: false, inherits: &[1] }),
|
||||
("ForStatementInit", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("JSXExpression", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("ArrayExpressionElement", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("LanguageVariant", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSNamespaceDeclarationBody", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("Statement", EnumDetails { is_fieldless: false, inherits: &[5, 6] }),
|
||||
("Argument", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("TSTupleElement", EnumDetails { is_fieldless: false, inherits: &[7] }),
|
||||
("PropertyKey", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("ImportDeclarationSpecifier", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("CommentKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("AccessorPropertyType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("AssignmentTargetProperty", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSMethodSignatureKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ArrowFunctionBody", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("LogicalOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("BinaryOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("CharacterClassContents", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("BindingPattern", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("AssignmentTargetMaybeDefault", EnumDetails { is_fieldless: false, inherits: &[2] }),
|
||||
("FormalParameterKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("CommentPosition", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("PropertyKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSTypeQueryExprName", EnumDetails { is_fieldless: false, inherits: &[8] }),
|
||||
("ImportPhase", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("FunctionType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSNamespaceDeclarationKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("JSXMemberExpressionObject", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ExportExportName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ForStatementLeft", EnumDetails { is_fieldless: false, inherits: &[2] }),
|
||||
("ImportImportName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("AssignmentTarget", EnumDetails { is_fieldless: false, inherits: &[3, 4] }),
|
||||
("JSXChild", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSSignature", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("AssignmentOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("PropertyDefinitionType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("MethodDefinitionKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("BigintBase", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ExportDefaultDeclarationKind", EnumDetails { is_fieldless: false, inherits: &[0] }),
|
||||
("TSTypePredicateName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("CharacterKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("AssignmentTargetPattern", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSTypeOperatorOperator", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("CommentContent", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSAccessibility", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("MethodDefinitionType", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSLiteral", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ModuleDeclaration", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("ExportLocalName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("BoundaryAssertionKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSImportTypeQualifier", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("JSXAttributeValue", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("LookAroundAssertionKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("ExportImportName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("TSTypeName", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("SimpleAssignmentTarget", EnumDetails { is_fieldless: false, inherits: &[1] }),
|
||||
("ImportOrExportKind", EnumDetails { is_fieldless: true, inherits: &[] }),
|
||||
("TSModuleReference", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
("MemberExpression", EnumDetails { is_fieldless: false, inherits: &[] }),
|
||||
],
|
||||
};
|
||||
|
||||
@@ -680,25 +679,32 @@ pub static INHERITED_ENUMS: [InheritedEnum; 9] = [
|
||||
discriminant: 37,
|
||||
},
|
||||
EnumVariant {
|
||||
name: "TSModuleDeclaration",
|
||||
inner_name: "TSModuleDeclaration",
|
||||
name: "TSExternalModuleDeclaration",
|
||||
inner_name: "TSExternalModuleDeclaration",
|
||||
inner_has_lifetime: true,
|
||||
is_boxed: true,
|
||||
discriminant: 38,
|
||||
},
|
||||
EnumVariant {
|
||||
name: "TSNamespaceDeclaration",
|
||||
inner_name: "TSNamespaceDeclaration",
|
||||
inner_has_lifetime: true,
|
||||
is_boxed: true,
|
||||
discriminant: 39,
|
||||
},
|
||||
EnumVariant {
|
||||
name: "TSGlobalDeclaration",
|
||||
inner_name: "TSGlobalDeclaration",
|
||||
inner_has_lifetime: true,
|
||||
is_boxed: true,
|
||||
discriminant: 39,
|
||||
discriminant: 40,
|
||||
},
|
||||
EnumVariant {
|
||||
name: "TSImportEqualsDeclaration",
|
||||
inner_name: "TSImportEqualsDeclaration",
|
||||
inner_has_lifetime: true,
|
||||
is_boxed: true,
|
||||
discriminant: 40,
|
||||
discriminant: 41,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -998,9 +998,15 @@ impl<'a> VisitMut<'a> for Utf8ToUtf16Converter<'_> {
|
||||
self.convert_offset(&mut it.span.end);
|
||||
}
|
||||
|
||||
fn visit_ts_module_declaration(&mut self, it: &mut TSModuleDeclaration<'a>) {
|
||||
fn visit_ts_external_module_declaration(&mut self, it: &mut TSExternalModuleDeclaration<'a>) {
|
||||
self.convert_offset(&mut it.span.start);
|
||||
walk_mut::walk_ts_module_declaration(self, it);
|
||||
walk_mut::walk_ts_external_module_declaration(self, it);
|
||||
self.convert_offset(&mut it.span.end);
|
||||
}
|
||||
|
||||
fn visit_ts_namespace_declaration(&mut self, it: &mut TSNamespaceDeclaration<'a>) {
|
||||
self.convert_offset(&mut it.span.start);
|
||||
walk_mut::walk_ts_namespace_declaration(self, it);
|
||||
self.convert_offset(&mut it.span.end);
|
||||
}
|
||||
|
||||
|
||||
@@ -1070,18 +1070,18 @@ pub trait Visit<'a>: Sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration(&mut self, it: &TSModuleDeclaration<'a>) {
|
||||
walk_ts_module_declaration(self, it);
|
||||
fn visit_ts_external_module_declaration(&mut self, it: &TSExternalModuleDeclaration<'a>) {
|
||||
walk_ts_external_module_declaration(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration_name(&mut self, it: &TSModuleDeclarationName<'a>) {
|
||||
walk_ts_module_declaration_name(self, it);
|
||||
fn visit_ts_namespace_declaration(&mut self, it: &TSNamespaceDeclaration<'a>) {
|
||||
walk_ts_namespace_declaration(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration_body(&mut self, it: &TSModuleDeclarationBody<'a>) {
|
||||
walk_ts_module_declaration_body(self, it);
|
||||
fn visit_ts_namespace_declaration_body(&mut self, it: &TSNamespaceDeclarationBody<'a>) {
|
||||
walk_ts_namespace_declaration_body(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -2092,7 +2092,10 @@ pub mod walk {
|
||||
Declaration::TSTypeAliasDeclaration(it) => visitor.visit_ts_type_alias_declaration(it),
|
||||
Declaration::TSInterfaceDeclaration(it) => visitor.visit_ts_interface_declaration(it),
|
||||
Declaration::TSEnumDeclaration(it) => visitor.visit_ts_enum_declaration(it),
|
||||
Declaration::TSModuleDeclaration(it) => visitor.visit_ts_module_declaration(it),
|
||||
Declaration::TSExternalModuleDeclaration(it) => {
|
||||
visitor.visit_ts_external_module_declaration(it)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(it) => visitor.visit_ts_namespace_declaration(it),
|
||||
Declaration::TSGlobalDeclaration(it) => visitor.visit_ts_global_declaration(it),
|
||||
Declaration::TSImportEqualsDeclaration(it) => {
|
||||
visitor.visit_ts_import_equals_declaration(it)
|
||||
@@ -3900,18 +3903,18 @@ pub mod walk {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration<'a, V: Visit<'a>>(
|
||||
pub fn walk_ts_external_module_declaration<'a, V: Visit<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &TSModuleDeclaration<'a>,
|
||||
it: &TSExternalModuleDeclaration<'a>,
|
||||
) {
|
||||
let kind = AstKind::TSModuleDeclaration(visitor.alloc(it));
|
||||
let kind = AstKind::TSExternalModuleDeclaration(visitor.alloc(it));
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&it.span);
|
||||
visitor.visit_ts_module_declaration_name(&it.id);
|
||||
visitor.visit_string_literal(&it.id);
|
||||
visitor.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if it.body.as_ref().is_some_and(TSModuleDeclarationBody::has_use_strict_directive) {
|
||||
if it.body.as_ref().is_some_and(|body| body.has_use_strict_directive()) {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
@@ -3919,35 +3922,47 @@ pub mod walk {
|
||||
&it.scope_id,
|
||||
);
|
||||
if let Some(body) = &it.body {
|
||||
visitor.visit_ts_module_declaration_body(body);
|
||||
visitor.visit_ts_module_block(body);
|
||||
}
|
||||
visitor.leave_scope();
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration_name<'a, V: Visit<'a>>(
|
||||
pub fn walk_ts_namespace_declaration<'a, V: Visit<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &TSModuleDeclarationName<'a>,
|
||||
it: &TSNamespaceDeclaration<'a>,
|
||||
) {
|
||||
// No `AstKind` for this type
|
||||
match it {
|
||||
TSModuleDeclarationName::Identifier(it) => visitor.visit_binding_identifier(it),
|
||||
TSModuleDeclarationName::StringLiteral(it) => visitor.visit_string_literal(it),
|
||||
}
|
||||
let kind = AstKind::TSNamespaceDeclaration(visitor.alloc(it));
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&it.span);
|
||||
visitor.visit_binding_identifier(&it.id);
|
||||
visitor.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if it.body.has_use_strict_directive() {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
},
|
||||
&it.scope_id,
|
||||
);
|
||||
visitor.visit_ts_namespace_declaration_body(&it.body);
|
||||
visitor.leave_scope();
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration_body<'a, V: Visit<'a>>(
|
||||
pub fn walk_ts_namespace_declaration_body<'a, V: Visit<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &TSModuleDeclarationBody<'a>,
|
||||
it: &TSNamespaceDeclarationBody<'a>,
|
||||
) {
|
||||
// No `AstKind` for this type
|
||||
match it {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(it) => {
|
||||
visitor.visit_ts_module_declaration(it)
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(it) => {
|
||||
visitor.visit_ts_namespace_declaration(it)
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(it) => visitor.visit_ts_module_block(it),
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(it) => visitor.visit_ts_module_block(it),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -849,18 +849,18 @@ pub trait VisitJs<'a>: Sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration(&mut self, it: &TSModuleDeclaration<'a>) {
|
||||
walk_ts_module_declaration(self, it);
|
||||
fn visit_ts_external_module_declaration(&mut self, it: &TSExternalModuleDeclaration<'a>) {
|
||||
walk_ts_external_module_declaration(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration_name(&mut self, it: &TSModuleDeclarationName<'a>) {
|
||||
walk_ts_module_declaration_name(self, it);
|
||||
fn visit_ts_namespace_declaration(&mut self, it: &TSNamespaceDeclaration<'a>) {
|
||||
walk_ts_namespace_declaration(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration_body(&mut self, it: &TSModuleDeclarationBody<'a>) {
|
||||
walk_ts_module_declaration_body(self, it);
|
||||
fn visit_ts_namespace_declaration_body(&mut self, it: &TSNamespaceDeclarationBody<'a>) {
|
||||
walk_ts_namespace_declaration_body(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -1761,7 +1761,10 @@ pub mod walk_js {
|
||||
}
|
||||
Declaration::ClassDeclaration(it) => visitor.visit_class(it),
|
||||
Declaration::TSEnumDeclaration(it) => visitor.visit_ts_enum_declaration(it),
|
||||
Declaration::TSModuleDeclaration(it) => visitor.visit_ts_module_declaration(it),
|
||||
Declaration::TSExternalModuleDeclaration(it) => {
|
||||
visitor.visit_ts_external_module_declaration(it)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(it) => visitor.visit_ts_namespace_declaration(it),
|
||||
Declaration::TSGlobalDeclaration(it) => visitor.visit_ts_global_declaration(it),
|
||||
Declaration::TSImportEqualsDeclaration(it) => {
|
||||
visitor.visit_ts_import_equals_declaration(it)
|
||||
@@ -2979,18 +2982,18 @@ pub mod walk_js {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration<'a, V: VisitJs<'a>>(
|
||||
pub fn walk_ts_external_module_declaration<'a, V: VisitJs<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &TSModuleDeclaration<'a>,
|
||||
it: &TSExternalModuleDeclaration<'a>,
|
||||
) {
|
||||
let kind = AstKind::TSModuleDeclaration(visitor.alloc(it));
|
||||
let kind = AstKind::TSExternalModuleDeclaration(visitor.alloc(it));
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&it.span);
|
||||
visitor.visit_ts_module_declaration_name(&it.id);
|
||||
visitor.visit_string_literal(&it.id);
|
||||
visitor.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if it.body.as_ref().is_some_and(TSModuleDeclarationBody::has_use_strict_directive) {
|
||||
if it.body.as_ref().is_some_and(|body| body.has_use_strict_directive()) {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
@@ -2998,35 +3001,47 @@ pub mod walk_js {
|
||||
&it.scope_id,
|
||||
);
|
||||
if let Some(body) = &it.body {
|
||||
visitor.visit_ts_module_declaration_body(body);
|
||||
visitor.visit_ts_module_block(body);
|
||||
}
|
||||
visitor.leave_scope();
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration_name<'a, V: VisitJs<'a>>(
|
||||
pub fn walk_ts_namespace_declaration<'a, V: VisitJs<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &TSModuleDeclarationName<'a>,
|
||||
it: &TSNamespaceDeclaration<'a>,
|
||||
) {
|
||||
// No `AstKind` for this type
|
||||
match it {
|
||||
TSModuleDeclarationName::Identifier(it) => visitor.visit_binding_identifier(it),
|
||||
TSModuleDeclarationName::StringLiteral(it) => visitor.visit_string_literal(it),
|
||||
}
|
||||
let kind = AstKind::TSNamespaceDeclaration(visitor.alloc(it));
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&it.span);
|
||||
visitor.visit_binding_identifier(&it.id);
|
||||
visitor.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if it.body.has_use_strict_directive() {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
},
|
||||
&it.scope_id,
|
||||
);
|
||||
visitor.visit_ts_namespace_declaration_body(&it.body);
|
||||
visitor.leave_scope();
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration_body<'a, V: VisitJs<'a>>(
|
||||
pub fn walk_ts_namespace_declaration_body<'a, V: VisitJs<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &TSModuleDeclarationBody<'a>,
|
||||
it: &TSNamespaceDeclarationBody<'a>,
|
||||
) {
|
||||
// No `AstKind` for this type
|
||||
match it {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(it) => {
|
||||
visitor.visit_ts_module_declaration(it)
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(it) => {
|
||||
visitor.visit_ts_namespace_declaration(it)
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(it) => visitor.visit_ts_module_block(it),
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(it) => visitor.visit_ts_module_block(it),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -841,18 +841,18 @@ pub trait VisitJsMut<'a>: Sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration(&mut self, it: &mut TSModuleDeclaration<'a>) {
|
||||
walk_ts_module_declaration(self, it);
|
||||
fn visit_ts_external_module_declaration(&mut self, it: &mut TSExternalModuleDeclaration<'a>) {
|
||||
walk_ts_external_module_declaration(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration_name(&mut self, it: &mut TSModuleDeclarationName<'a>) {
|
||||
walk_ts_module_declaration_name(self, it);
|
||||
fn visit_ts_namespace_declaration(&mut self, it: &mut TSNamespaceDeclaration<'a>) {
|
||||
walk_ts_namespace_declaration(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration_body(&mut self, it: &mut TSModuleDeclarationBody<'a>) {
|
||||
walk_ts_module_declaration_body(self, it);
|
||||
fn visit_ts_namespace_declaration_body(&mut self, it: &mut TSNamespaceDeclarationBody<'a>) {
|
||||
walk_ts_namespace_declaration_body(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -1804,7 +1804,10 @@ pub mod walk_js_mut {
|
||||
}
|
||||
Declaration::ClassDeclaration(it) => visitor.visit_class(it),
|
||||
Declaration::TSEnumDeclaration(it) => visitor.visit_ts_enum_declaration(it),
|
||||
Declaration::TSModuleDeclaration(it) => visitor.visit_ts_module_declaration(it),
|
||||
Declaration::TSExternalModuleDeclaration(it) => {
|
||||
visitor.visit_ts_external_module_declaration(it)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(it) => visitor.visit_ts_namespace_declaration(it),
|
||||
Declaration::TSGlobalDeclaration(it) => visitor.visit_ts_global_declaration(it),
|
||||
Declaration::TSImportEqualsDeclaration(it) => {
|
||||
visitor.visit_ts_import_equals_declaration(it)
|
||||
@@ -3132,18 +3135,18 @@ pub mod walk_js_mut {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration<'a, V: VisitJsMut<'a>>(
|
||||
pub fn walk_ts_external_module_declaration<'a, V: VisitJsMut<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &mut TSModuleDeclaration<'a>,
|
||||
it: &mut TSExternalModuleDeclaration<'a>,
|
||||
) {
|
||||
let kind = AstType::TSModuleDeclaration;
|
||||
let kind = AstType::TSExternalModuleDeclaration;
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&mut it.span);
|
||||
visitor.visit_ts_module_declaration_name(&mut it.id);
|
||||
visitor.visit_string_literal(&mut it.id);
|
||||
visitor.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if it.body.as_ref().is_some_and(TSModuleDeclarationBody::has_use_strict_directive) {
|
||||
if it.body.as_ref().is_some_and(|body| body.has_use_strict_directive()) {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
@@ -3151,35 +3154,47 @@ pub mod walk_js_mut {
|
||||
&it.scope_id,
|
||||
);
|
||||
if let Some(body) = &mut it.body {
|
||||
visitor.visit_ts_module_declaration_body(body);
|
||||
visitor.visit_ts_module_block(body);
|
||||
}
|
||||
visitor.leave_scope();
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration_name<'a, V: VisitJsMut<'a>>(
|
||||
pub fn walk_ts_namespace_declaration<'a, V: VisitJsMut<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &mut TSModuleDeclarationName<'a>,
|
||||
it: &mut TSNamespaceDeclaration<'a>,
|
||||
) {
|
||||
// No `AstType` for this type
|
||||
match it {
|
||||
TSModuleDeclarationName::Identifier(it) => visitor.visit_binding_identifier(it),
|
||||
TSModuleDeclarationName::StringLiteral(it) => visitor.visit_string_literal(it),
|
||||
}
|
||||
let kind = AstType::TSNamespaceDeclaration;
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&mut it.span);
|
||||
visitor.visit_binding_identifier(&mut it.id);
|
||||
visitor.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if it.body.has_use_strict_directive() {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
},
|
||||
&it.scope_id,
|
||||
);
|
||||
visitor.visit_ts_namespace_declaration_body(&mut it.body);
|
||||
visitor.leave_scope();
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration_body<'a, V: VisitJsMut<'a>>(
|
||||
pub fn walk_ts_namespace_declaration_body<'a, V: VisitJsMut<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &mut TSModuleDeclarationBody<'a>,
|
||||
it: &mut TSNamespaceDeclarationBody<'a>,
|
||||
) {
|
||||
// No `AstType` for this type
|
||||
match it {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(it) => {
|
||||
visitor.visit_ts_module_declaration(it)
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(it) => {
|
||||
visitor.visit_ts_namespace_declaration(it)
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(it) => visitor.visit_ts_module_block(it),
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(it) => visitor.visit_ts_module_block(it),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1062,18 +1062,18 @@ pub trait VisitMut<'a>: Sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration(&mut self, it: &mut TSModuleDeclaration<'a>) {
|
||||
walk_ts_module_declaration(self, it);
|
||||
fn visit_ts_external_module_declaration(&mut self, it: &mut TSExternalModuleDeclaration<'a>) {
|
||||
walk_ts_external_module_declaration(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration_name(&mut self, it: &mut TSModuleDeclarationName<'a>) {
|
||||
walk_ts_module_declaration_name(self, it);
|
||||
fn visit_ts_namespace_declaration(&mut self, it: &mut TSNamespaceDeclaration<'a>) {
|
||||
walk_ts_namespace_declaration(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration_body(&mut self, it: &mut TSModuleDeclarationBody<'a>) {
|
||||
walk_ts_module_declaration_body(self, it);
|
||||
fn visit_ts_namespace_declaration_body(&mut self, it: &mut TSNamespaceDeclarationBody<'a>) {
|
||||
walk_ts_namespace_declaration_body(self, it);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -2129,7 +2129,10 @@ pub mod walk_mut {
|
||||
Declaration::TSTypeAliasDeclaration(it) => visitor.visit_ts_type_alias_declaration(it),
|
||||
Declaration::TSInterfaceDeclaration(it) => visitor.visit_ts_interface_declaration(it),
|
||||
Declaration::TSEnumDeclaration(it) => visitor.visit_ts_enum_declaration(it),
|
||||
Declaration::TSModuleDeclaration(it) => visitor.visit_ts_module_declaration(it),
|
||||
Declaration::TSExternalModuleDeclaration(it) => {
|
||||
visitor.visit_ts_external_module_declaration(it)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(it) => visitor.visit_ts_namespace_declaration(it),
|
||||
Declaration::TSGlobalDeclaration(it) => visitor.visit_ts_global_declaration(it),
|
||||
Declaration::TSImportEqualsDeclaration(it) => {
|
||||
visitor.visit_ts_import_equals_declaration(it)
|
||||
@@ -4117,18 +4120,18 @@ pub mod walk_mut {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration<'a, V: VisitMut<'a>>(
|
||||
pub fn walk_ts_external_module_declaration<'a, V: VisitMut<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &mut TSModuleDeclaration<'a>,
|
||||
it: &mut TSExternalModuleDeclaration<'a>,
|
||||
) {
|
||||
let kind = AstType::TSModuleDeclaration;
|
||||
let kind = AstType::TSExternalModuleDeclaration;
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&mut it.span);
|
||||
visitor.visit_ts_module_declaration_name(&mut it.id);
|
||||
visitor.visit_string_literal(&mut it.id);
|
||||
visitor.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if it.body.as_ref().is_some_and(TSModuleDeclarationBody::has_use_strict_directive) {
|
||||
if it.body.as_ref().is_some_and(|body| body.has_use_strict_directive()) {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
@@ -4136,35 +4139,47 @@ pub mod walk_mut {
|
||||
&it.scope_id,
|
||||
);
|
||||
if let Some(body) = &mut it.body {
|
||||
visitor.visit_ts_module_declaration_body(body);
|
||||
visitor.visit_ts_module_block(body);
|
||||
}
|
||||
visitor.leave_scope();
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration_name<'a, V: VisitMut<'a>>(
|
||||
pub fn walk_ts_namespace_declaration<'a, V: VisitMut<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &mut TSModuleDeclarationName<'a>,
|
||||
it: &mut TSNamespaceDeclaration<'a>,
|
||||
) {
|
||||
// No `AstType` for this type
|
||||
match it {
|
||||
TSModuleDeclarationName::Identifier(it) => visitor.visit_binding_identifier(it),
|
||||
TSModuleDeclarationName::StringLiteral(it) => visitor.visit_string_literal(it),
|
||||
}
|
||||
let kind = AstType::TSNamespaceDeclaration;
|
||||
visitor.enter_node(kind);
|
||||
visitor.visit_span(&mut it.span);
|
||||
visitor.visit_binding_identifier(&mut it.id);
|
||||
visitor.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if it.body.has_use_strict_directive() {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
},
|
||||
&it.scope_id,
|
||||
);
|
||||
visitor.visit_ts_namespace_declaration_body(&mut it.body);
|
||||
visitor.leave_scope();
|
||||
visitor.leave_node(kind);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn walk_ts_module_declaration_body<'a, V: VisitMut<'a>>(
|
||||
pub fn walk_ts_namespace_declaration_body<'a, V: VisitMut<'a>>(
|
||||
visitor: &mut V,
|
||||
it: &mut TSModuleDeclarationBody<'a>,
|
||||
it: &mut TSNamespaceDeclarationBody<'a>,
|
||||
) {
|
||||
// No `AstType` for this type
|
||||
match it {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(it) => {
|
||||
visitor.visit_ts_module_declaration(it)
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(it) => {
|
||||
visitor.visit_ts_namespace_declaration(it)
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(it) => visitor.visit_ts_module_block(it),
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(it) => visitor.visit_ts_module_block(it),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,13 @@ impl Gen for Statement<'_> {
|
||||
Self::WithStatement(stmt) => stmt.print(p, ctx),
|
||||
Self::DebuggerStatement(stmt) => stmt.print(p, ctx),
|
||||
// TypeScript-specific (less common)
|
||||
Self::TSModuleDeclaration(decl) => {
|
||||
Self::TSExternalModuleDeclaration(decl) => {
|
||||
p.print_comments_at(decl.span.start);
|
||||
p.print_indent();
|
||||
decl.print(p, ctx);
|
||||
p.print_soft_newline();
|
||||
}
|
||||
Self::TSNamespaceDeclaration(decl) => {
|
||||
p.print_comments_at(decl.span.start);
|
||||
p.print_indent();
|
||||
decl.print(p, ctx);
|
||||
@@ -1070,7 +1076,8 @@ impl Gen for ExportDeclaration<'_> {
|
||||
Declaration::VariableDeclaration(decl) => decl.print(p, ctx),
|
||||
Declaration::FunctionDeclaration(decl) => decl.print(p, ctx),
|
||||
Declaration::ClassDeclaration(decl) => decl.print(p, ctx),
|
||||
Declaration::TSModuleDeclaration(decl) => decl.print(p, ctx),
|
||||
Declaration::TSExternalModuleDeclaration(decl) => decl.print(p, ctx),
|
||||
Declaration::TSNamespaceDeclaration(decl) => decl.print(p, ctx),
|
||||
Declaration::TSGlobalDeclaration(decl) => decl.print(p, ctx),
|
||||
Declaration::TSTypeAliasDeclaration(decl) => decl.print(p, ctx),
|
||||
Declaration::TSInterfaceDeclaration(decl) => decl.print(p, ctx),
|
||||
@@ -3966,7 +3973,26 @@ impl Gen for TSNamedTupleMember<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Gen for TSModuleDeclaration<'_> {
|
||||
impl Gen for TSExternalModuleDeclaration<'_> {
|
||||
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
|
||||
if self.declare {
|
||||
p.print_str("declare ");
|
||||
}
|
||||
p.print_str("module");
|
||||
p.print_space_before_identifier();
|
||||
p.print_string_literal(&self.id, false);
|
||||
|
||||
if let Some(body) = &self.body {
|
||||
p.print_soft_space();
|
||||
body.print(p, ctx);
|
||||
} else {
|
||||
p.print_semicolon();
|
||||
}
|
||||
p.needs_semicolon = false;
|
||||
}
|
||||
}
|
||||
|
||||
impl Gen for TSNamespaceDeclaration<'_> {
|
||||
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
|
||||
if self.declare {
|
||||
p.print_str("declare ");
|
||||
@@ -3975,42 +4001,25 @@ impl Gen for TSModuleDeclaration<'_> {
|
||||
p.print_space_before_identifier();
|
||||
self.id.print(p, ctx);
|
||||
|
||||
if let Some(body) = &self.body {
|
||||
let mut body = body;
|
||||
loop {
|
||||
match body {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(b) => {
|
||||
p.print_ascii_byte(b'.');
|
||||
b.id.print(p, ctx);
|
||||
if let Some(b) = &b.body {
|
||||
body = b;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(body) => {
|
||||
p.print_soft_space();
|
||||
body.print(p, ctx);
|
||||
break;
|
||||
}
|
||||
let mut body = &self.body;
|
||||
loop {
|
||||
match body {
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(namespace) => {
|
||||
p.print_ascii_byte(b'.');
|
||||
namespace.id.print(p, ctx);
|
||||
body = &namespace.body;
|
||||
}
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(body) => {
|
||||
p.print_soft_space();
|
||||
body.print(p, ctx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.print_semicolon();
|
||||
}
|
||||
p.needs_semicolon = false;
|
||||
}
|
||||
}
|
||||
|
||||
impl Gen for TSModuleDeclarationName<'_> {
|
||||
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
|
||||
match self {
|
||||
Self::Identifier(ident) => ident.print(p, ctx),
|
||||
Self::StringLiteral(s) => p.print_string_literal(s, false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Gen for TSGlobalDeclaration<'_> {
|
||||
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
|
||||
if self.declare {
|
||||
|
||||
@@ -92,7 +92,8 @@ impl<'a> MayHaveSideEffects<'a> for Declaration<'a> {
|
||||
Declaration::ClassDeclaration(class_decl) => class_decl.may_have_side_effects(ctx),
|
||||
Declaration::TSEnumDeclaration(_)
|
||||
| Declaration::TSImportEqualsDeclaration(_)
|
||||
| Declaration::TSModuleDeclaration(_)
|
||||
| Declaration::TSExternalModuleDeclaration(_)
|
||||
| Declaration::TSNamespaceDeclaration(_)
|
||||
| Declaration::TSGlobalDeclaration(_)
|
||||
| Declaration::TSInterfaceDeclaration(_)
|
||||
| Declaration::TSTypeAliasDeclaration(_) => unreachable!(),
|
||||
|
||||
@@ -193,7 +193,8 @@ pub enum AstNodes<'a> {
|
||||
TSIndexSignatureName(&'a AstNode<'a, TSIndexSignatureName<'a>>),
|
||||
TSInterfaceHeritage(&'a AstNode<'a, TSInterfaceHeritage<'a>>),
|
||||
TSTypePredicate(&'a AstNode<'a, TSTypePredicate<'a>>),
|
||||
TSModuleDeclaration(&'a AstNode<'a, TSModuleDeclaration<'a>>),
|
||||
TSExternalModuleDeclaration(&'a AstNode<'a, TSExternalModuleDeclaration<'a>>),
|
||||
TSNamespaceDeclaration(&'a AstNode<'a, TSNamespaceDeclaration<'a>>),
|
||||
TSGlobalDeclaration(&'a AstNode<'a, TSGlobalDeclaration<'a>>),
|
||||
TSModuleBlock(&'a AstNode<'a, TSModuleBlock<'a>>),
|
||||
TSTypeLiteral(&'a AstNode<'a, TSTypeLiteral<'a>>),
|
||||
@@ -395,7 +396,8 @@ impl AstNodes<'_> {
|
||||
Self::TSIndexSignatureName(n) => n.span(),
|
||||
Self::TSInterfaceHeritage(n) => n.span(),
|
||||
Self::TSTypePredicate(n) => n.span(),
|
||||
Self::TSModuleDeclaration(n) => n.span(),
|
||||
Self::TSExternalModuleDeclaration(n) => n.span(),
|
||||
Self::TSNamespaceDeclaration(n) => n.span(),
|
||||
Self::TSGlobalDeclaration(n) => n.span(),
|
||||
Self::TSModuleBlock(n) => n.span(),
|
||||
Self::TSTypeLiteral(n) => n.span(),
|
||||
@@ -597,7 +599,8 @@ impl AstNodes<'_> {
|
||||
Self::TSIndexSignatureName(n) => n.parent(),
|
||||
Self::TSInterfaceHeritage(n) => n.parent(),
|
||||
Self::TSTypePredicate(n) => n.parent(),
|
||||
Self::TSModuleDeclaration(n) => n.parent(),
|
||||
Self::TSExternalModuleDeclaration(n) => n.parent(),
|
||||
Self::TSNamespaceDeclaration(n) => n.parent(),
|
||||
Self::TSGlobalDeclaration(n) => n.parent(),
|
||||
Self::TSModuleBlock(n) => n.parent(),
|
||||
Self::TSTypeLiteral(n) => n.parent(),
|
||||
@@ -794,7 +797,8 @@ impl AstNodes<'_> {
|
||||
Self::TSIndexSignatureName(_) => "TSIndexSignatureName",
|
||||
Self::TSInterfaceHeritage(_) => "TSInterfaceHeritage",
|
||||
Self::TSTypePredicate(_) => "TSTypePredicate",
|
||||
Self::TSModuleDeclaration(_) => "TSModuleDeclaration",
|
||||
Self::TSExternalModuleDeclaration(_) => "TSExternalModuleDeclaration",
|
||||
Self::TSNamespaceDeclaration(_) => "TSNamespaceDeclaration",
|
||||
Self::TSGlobalDeclaration(_) => "TSGlobalDeclaration",
|
||||
Self::TSModuleBlock(_) => "TSModuleBlock",
|
||||
Self::TSTypeLiteral(_) => "TSTypeLiteral",
|
||||
@@ -3242,8 +3246,16 @@ impl<'a> AstNode<'a, Declaration<'a>> {
|
||||
following_span_start: self.following_span_start,
|
||||
}))
|
||||
}
|
||||
Declaration::TSModuleDeclaration(s) => {
|
||||
AstNodes::TSModuleDeclaration(self.allocator.alloc(AstNode {
|
||||
Declaration::TSExternalModuleDeclaration(s) => {
|
||||
AstNodes::TSExternalModuleDeclaration(self.allocator.alloc(AstNode {
|
||||
inner: s.as_ref(),
|
||||
parent,
|
||||
allocator: self.allocator,
|
||||
following_span_start: self.following_span_start,
|
||||
}))
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(s) => {
|
||||
AstNodes::TSNamespaceDeclaration(self.allocator.alloc(AstNode {
|
||||
inner: s.as_ref(),
|
||||
parent,
|
||||
allocator: self.allocator,
|
||||
@@ -9515,38 +9527,81 @@ impl<'a> AstNode<'a, TSTypePredicateName<'a>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a, TSModuleDeclaration<'a>> {
|
||||
impl<'a> AstNode<'a, TSExternalModuleDeclaration<'a>> {
|
||||
#[inline]
|
||||
pub fn node_id(&self) -> NodeId {
|
||||
self.inner.node_id()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> &AstNode<'a, TSModuleDeclarationName<'a>> {
|
||||
let following_span_start = self.inner.body.as_ref().map_or(0, |n| n.span().start);
|
||||
pub fn id(&self) -> &AstNode<'a, StringLiteral<'a>> {
|
||||
let following_span_start = self.inner.body.as_deref().map_or(0, |n| n.span().start);
|
||||
self.allocator.alloc(AstNode {
|
||||
inner: &self.inner.id,
|
||||
allocator: self.allocator,
|
||||
parent: AstNodes::TSModuleDeclaration(transmute_self(self)),
|
||||
parent: AstNodes::TSExternalModuleDeclaration(transmute_self(self)),
|
||||
following_span_start,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn body(&self) -> Option<&AstNode<'a, TSModuleDeclarationBody<'a>>> {
|
||||
pub fn body(&self) -> Option<&AstNode<'a, TSModuleBlock<'a>>> {
|
||||
let following_span_start = 0;
|
||||
self.allocator
|
||||
.alloc(self.inner.body.as_ref().map(|inner| AstNode {
|
||||
inner,
|
||||
inner: inner.as_ref(),
|
||||
allocator: self.allocator,
|
||||
parent: AstNodes::TSModuleDeclaration(transmute_self(self)),
|
||||
parent: AstNodes::TSExternalModuleDeclaration(transmute_self(self)),
|
||||
following_span_start,
|
||||
}))
|
||||
.as_ref()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(&self) -> TSModuleDeclarationKind {
|
||||
pub fn declare(&self) -> bool {
|
||||
self.inner.declare
|
||||
}
|
||||
|
||||
pub fn format_leading_comments(&self, f: &mut JsFormatter<'_, 'a>) {
|
||||
format_leading_comments(self.span()).fmt(f);
|
||||
}
|
||||
|
||||
pub fn format_trailing_comments(&self, f: &mut JsFormatter<'_, 'a>) {
|
||||
format_trailing_comments(self.parent.span(), self.inner.span(), self.following_span_start)
|
||||
.fmt(f);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a, TSNamespaceDeclaration<'a>> {
|
||||
#[inline]
|
||||
pub fn node_id(&self) -> NodeId {
|
||||
self.inner.node_id()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> &AstNode<'a, BindingIdentifier<'a>> {
|
||||
let following_span_start = self.inner.body.span().start;
|
||||
self.allocator.alloc(AstNode {
|
||||
inner: &self.inner.id,
|
||||
allocator: self.allocator,
|
||||
parent: AstNodes::TSNamespaceDeclaration(transmute_self(self)),
|
||||
following_span_start,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn body(&self) -> &AstNode<'a, TSNamespaceDeclarationBody<'a>> {
|
||||
let following_span_start = 0;
|
||||
self.allocator.alloc(AstNode {
|
||||
inner: &self.inner.body,
|
||||
allocator: self.allocator,
|
||||
parent: AstNodes::TSNamespaceDeclaration(transmute_self(self)),
|
||||
following_span_start,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(&self) -> TSNamespaceDeclarationKind {
|
||||
self.inner.kind
|
||||
}
|
||||
|
||||
@@ -9565,46 +9620,20 @@ impl<'a> AstNode<'a, TSModuleDeclaration<'a>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a, TSModuleDeclarationName<'a>> {
|
||||
impl<'a> AstNode<'a, TSNamespaceDeclarationBody<'a>> {
|
||||
#[inline]
|
||||
pub fn as_ast_nodes(&self) -> &AstNodes<'a> {
|
||||
let parent = self.parent;
|
||||
let node = match self.inner {
|
||||
TSModuleDeclarationName::Identifier(s) => {
|
||||
AstNodes::BindingIdentifier(self.allocator.alloc(AstNode {
|
||||
inner: s,
|
||||
parent,
|
||||
allocator: self.allocator,
|
||||
following_span_start: self.following_span_start,
|
||||
}))
|
||||
}
|
||||
TSModuleDeclarationName::StringLiteral(s) => {
|
||||
AstNodes::StringLiteral(self.allocator.alloc(AstNode {
|
||||
inner: s,
|
||||
parent,
|
||||
allocator: self.allocator,
|
||||
following_span_start: self.following_span_start,
|
||||
}))
|
||||
}
|
||||
};
|
||||
self.allocator.alloc(node)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a, TSModuleDeclarationBody<'a>> {
|
||||
#[inline]
|
||||
pub fn as_ast_nodes(&self) -> &AstNodes<'a> {
|
||||
let parent = self.parent;
|
||||
let node = match self.inner {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(s) => {
|
||||
AstNodes::TSModuleDeclaration(self.allocator.alloc(AstNode {
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(s) => {
|
||||
AstNodes::TSNamespaceDeclaration(self.allocator.alloc(AstNode {
|
||||
inner: s.as_ref(),
|
||||
parent,
|
||||
allocator: self.allocator,
|
||||
following_span_start: self.following_span_start,
|
||||
}))
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(s) => {
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(s) => {
|
||||
AstNodes::TSModuleBlock(self.allocator.alloc(AstNode {
|
||||
inner: s.as_ref(),
|
||||
parent,
|
||||
|
||||
@@ -1885,9 +1885,19 @@ impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, Declaration<'a>> {
|
||||
})
|
||||
.fmt(f);
|
||||
}
|
||||
Declaration::TSModuleDeclaration(inner) => {
|
||||
Declaration::TSExternalModuleDeclaration(inner) => {
|
||||
allocator
|
||||
.alloc(AstNode::<TSModuleDeclaration> {
|
||||
.alloc(AstNode::<TSExternalModuleDeclaration> {
|
||||
inner,
|
||||
parent,
|
||||
allocator,
|
||||
following_span_start: self.following_span_start,
|
||||
})
|
||||
.fmt(f);
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(inner) => {
|
||||
allocator
|
||||
.alloc(AstNode::<TSNamespaceDeclaration> {
|
||||
inner,
|
||||
parent,
|
||||
allocator,
|
||||
@@ -5122,7 +5132,7 @@ impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSTypePredicateName<'a>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSModuleDeclaration<'a>> {
|
||||
impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSExternalModuleDeclaration<'a>> {
|
||||
fn fmt(&self, f: &mut JsFormatter<'_, 'a>) {
|
||||
let is_suppressed = f.comments().is_suppressed(self.span().start);
|
||||
self.format_leading_comments(f);
|
||||
@@ -5135,45 +5145,28 @@ impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSModuleDeclaration<'a>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSModuleDeclarationName<'a>> {
|
||||
#[inline]
|
||||
impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSNamespaceDeclaration<'a>> {
|
||||
fn fmt(&self, f: &mut JsFormatter<'_, 'a>) {
|
||||
let allocator = self.allocator;
|
||||
let parent = self.parent;
|
||||
match self.inner {
|
||||
TSModuleDeclarationName::Identifier(inner) => {
|
||||
allocator
|
||||
.alloc(AstNode::<BindingIdentifier> {
|
||||
inner,
|
||||
parent,
|
||||
allocator,
|
||||
following_span_start: self.following_span_start,
|
||||
})
|
||||
.fmt(f);
|
||||
}
|
||||
TSModuleDeclarationName::StringLiteral(inner) => {
|
||||
allocator
|
||||
.alloc(AstNode::<StringLiteral> {
|
||||
inner,
|
||||
parent,
|
||||
allocator,
|
||||
following_span_start: self.following_span_start,
|
||||
})
|
||||
.fmt(f);
|
||||
}
|
||||
let is_suppressed = f.comments().is_suppressed(self.span().start);
|
||||
self.format_leading_comments(f);
|
||||
if is_suppressed {
|
||||
FormatSuppressedNode(self.span()).fmt(f);
|
||||
} else {
|
||||
self.write(f);
|
||||
}
|
||||
self.format_trailing_comments(f);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSModuleDeclarationBody<'a>> {
|
||||
impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSNamespaceDeclarationBody<'a>> {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut JsFormatter<'_, 'a>) {
|
||||
let allocator = self.allocator;
|
||||
let parent = self.parent;
|
||||
match self.inner {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(inner) => {
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(inner) => {
|
||||
allocator
|
||||
.alloc(AstNode::<TSModuleDeclaration> {
|
||||
.alloc(AstNode::<TSNamespaceDeclaration> {
|
||||
inner,
|
||||
parent,
|
||||
allocator,
|
||||
@@ -5181,7 +5174,7 @@ impl<'a> Format<'a, JsFormatContext<'a>> for AstNode<'a, TSModuleDeclarationBody
|
||||
})
|
||||
.fmt(f);
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(inner) => {
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(inner) => {
|
||||
allocator
|
||||
.alloc(AstNode::<TSModuleBlock> {
|
||||
inner,
|
||||
|
||||
@@ -80,7 +80,8 @@ fn is_non_collapsible(parent: &AstNodes<'_>) -> bool {
|
||||
| AstNodes::ForStatement(_)
|
||||
| AstNodes::WhileStatement(_)
|
||||
| AstNodes::DoWhileStatement(_)
|
||||
| AstNodes::TSModuleDeclaration(_)
|
||||
| AstNodes::TSExternalModuleDeclaration(_)
|
||||
| AstNodes::TSNamespaceDeclaration(_)
|
||||
| AstNodes::TSGlobalDeclaration(_) => false,
|
||||
AstNodes::CatchClause(catch) => {
|
||||
// prettier collapse the catch block when it don't have `finalizer`, insert a new line when it has `finalizer`
|
||||
|
||||
@@ -1941,7 +1941,23 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSTypePredicate<'a>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FormatWrite<'a> for AstNode<'a, TSModuleDeclaration<'a>> {
|
||||
impl<'a> FormatWrite<'a> for AstNode<'a, TSExternalModuleDeclaration<'a>> {
|
||||
fn write(&self, f: &mut JsFormatter<'_, 'a>) {
|
||||
if self.declare() {
|
||||
write!(f, ["declare", space()]);
|
||||
}
|
||||
|
||||
write!(f, ["module", space(), self.id()]);
|
||||
|
||||
if let Some(body) = self.body() {
|
||||
write!(f, [space(), body]);
|
||||
} else {
|
||||
write!(f, OptionalSemicolon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FormatWrite<'a> for AstNode<'a, TSNamespaceDeclaration<'a>> {
|
||||
fn write(&self, f: &mut JsFormatter<'_, 'a>) {
|
||||
if self.declare() {
|
||||
write!(f, ["declare", space()]);
|
||||
@@ -1951,29 +1967,21 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSModuleDeclaration<'a>> {
|
||||
|
||||
write!(f, [space(), self.id()]);
|
||||
|
||||
if let Some(body) = self.body() {
|
||||
let mut body = body;
|
||||
loop {
|
||||
match body.as_ast_nodes() {
|
||||
AstNodes::TSModuleDeclaration(b) => {
|
||||
write!(f, [".", b.id()]);
|
||||
if let Some(b) = &b.body() {
|
||||
body = b;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
AstNodes::TSModuleBlock(body) => {
|
||||
write!(f, [space(), body]);
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
let mut body = self.body();
|
||||
loop {
|
||||
match body.as_ast_nodes() {
|
||||
AstNodes::TSNamespaceDeclaration(namespace) => {
|
||||
write!(f, [".", namespace.id()]);
|
||||
body = namespace.body();
|
||||
}
|
||||
AstNodes::TSModuleBlock(body) => {
|
||||
write!(f, [space(), body]);
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
write!(f, OptionalSemicolon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,38 +124,52 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||
TSModuleBlock::boxed(SPAN, [], stmts, self)
|
||||
}
|
||||
|
||||
pub(crate) fn transform_ts_module_declaration(
|
||||
pub(crate) fn transform_ts_external_module_declaration(
|
||||
&mut self,
|
||||
decl: &ArenaBox<'a, TSModuleDeclaration<'a>>,
|
||||
) -> ArenaBox<'a, TSModuleDeclaration<'a>> {
|
||||
decl: &ArenaBox<'a, TSExternalModuleDeclaration<'a>>,
|
||||
) -> ArenaBox<'a, TSExternalModuleDeclaration<'a>> {
|
||||
if decl.declare {
|
||||
return decl.clone_in(self.allocator());
|
||||
}
|
||||
|
||||
let Some(body) = &decl.body else {
|
||||
let body = decl.body.as_ref().map(|block| self.transform_ts_module_block(block));
|
||||
TSExternalModuleDeclaration::boxed(
|
||||
decl.span,
|
||||
decl.id.clone_in(self.allocator()),
|
||||
body,
|
||||
self.is_declare(),
|
||||
self,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn transform_ts_namespace_declaration(
|
||||
&mut self,
|
||||
decl: &ArenaBox<'a, TSNamespaceDeclaration<'a>>,
|
||||
) -> ArenaBox<'a, TSNamespaceDeclaration<'a>> {
|
||||
if decl.declare {
|
||||
return decl.clone_in(self.allocator());
|
||||
};
|
||||
}
|
||||
|
||||
// Follows https://github.com/microsoft/TypeScript/pull/54134
|
||||
let kind = TSModuleDeclarationKind::Namespace;
|
||||
match body {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(inner_decl) => {
|
||||
let inner = self.transform_ts_module_declaration(inner_decl);
|
||||
TSModuleDeclaration::boxed(
|
||||
let kind = TSNamespaceDeclarationKind::Namespace;
|
||||
match &decl.body {
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(inner_decl) => {
|
||||
let inner = self.transform_ts_namespace_declaration(inner_decl);
|
||||
TSNamespaceDeclaration::boxed(
|
||||
decl.span,
|
||||
decl.id.clone_in(self.allocator()),
|
||||
Some(TSModuleDeclarationBody::TSModuleDeclaration(inner)),
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(inner),
|
||||
kind,
|
||||
self.is_declare(),
|
||||
self,
|
||||
)
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(block) => {
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => {
|
||||
let body = self.transform_ts_module_block(block);
|
||||
TSModuleDeclaration::boxed(
|
||||
TSNamespaceDeclaration::boxed(
|
||||
decl.span,
|
||||
decl.id.clone_in(self.allocator()),
|
||||
Some(TSModuleDeclarationBody::TSModuleBlock(body)),
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(body),
|
||||
kind,
|
||||
self.is_declare(),
|
||||
self,
|
||||
@@ -210,16 +224,19 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||
None
|
||||
}
|
||||
}
|
||||
Declaration::TSModuleDeclaration(decl) => {
|
||||
if !check_binding
|
||||
|| matches!(
|
||||
&decl.id,
|
||||
TSModuleDeclarationName::Identifier(ident)
|
||||
if self.scope.has_reference(&ident.name)
|
||||
)
|
||||
{
|
||||
Some(Declaration::TSModuleDeclaration(
|
||||
self.transform_ts_module_declaration(decl),
|
||||
Declaration::TSExternalModuleDeclaration(decl) => {
|
||||
if check_binding {
|
||||
None
|
||||
} else {
|
||||
Some(Declaration::TSExternalModuleDeclaration(
|
||||
self.transform_ts_external_module_declaration(decl),
|
||||
))
|
||||
}
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(decl) => {
|
||||
if !check_binding || self.scope.has_reference(&decl.id.name) {
|
||||
Some(Declaration::TSNamespaceDeclaration(
|
||||
self.transform_ts_namespace_declaration(decl),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -218,24 +218,20 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||
for (idx, &stmt) in stmts.iter().enumerate() {
|
||||
match stmt {
|
||||
match_declaration!(Statement) => {
|
||||
if let Statement::TSModuleDeclaration(decl) = stmt {
|
||||
if let Statement::TSExternalModuleDeclaration(decl) = stmt {
|
||||
// `declare module "foo" { ... }`
|
||||
// We need to emit it anyway
|
||||
if decl.id.is_string_literal() {
|
||||
let mut decl = decl.clone_in(self.allocator());
|
||||
// Remove export keyword from all statements in `declare module "xxx" { ... }`
|
||||
if let Some(body) =
|
||||
decl.body.as_mut().and_then(|body| body.as_module_block_mut())
|
||||
{
|
||||
Self::strip_export_keyword(&mut body.body);
|
||||
}
|
||||
|
||||
// We need to visit the module declaration to collect all references
|
||||
self.scope.visit_ts_module_declaration(decl.as_ref());
|
||||
|
||||
transformed_stmts[idx] = Some(Statement::TSModuleDeclaration(decl));
|
||||
transformed_count += 1;
|
||||
let mut decl = decl.clone_in(self.allocator());
|
||||
// Remove export keyword from all statements in `declare module "xxx" { ... }`
|
||||
if let Some(body) = &mut decl.body {
|
||||
Self::strip_export_keyword(&mut body.body);
|
||||
}
|
||||
|
||||
// We need to visit the module declaration to collect all references
|
||||
self.scope.visit_ts_external_module_declaration(decl.as_ref());
|
||||
|
||||
transformed_stmts[idx] = Some(Statement::TSExternalModuleDeclaration(decl));
|
||||
transformed_count += 1;
|
||||
} else if let Statement::TSGlobalDeclaration(decl) = stmt {
|
||||
// `declare global { ... }`
|
||||
// We need to emit it anyway
|
||||
@@ -524,14 +520,14 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||
|
||||
/// Collect exported names from a namespace declaration into `assignable_properties`.
|
||||
fn collect_namespace_properties(
|
||||
decl: &TSModuleDeclaration<'a>,
|
||||
decl: &TSNamespaceDeclaration<'a>,
|
||||
assignable_properties: &mut FxHashMap<&'a str, FxHashSet<Str<'a>>>,
|
||||
) {
|
||||
if decl.kind != TSModuleDeclarationKind::Namespace {
|
||||
if decl.kind != TSNamespaceDeclarationKind::Namespace {
|
||||
return;
|
||||
}
|
||||
let TSModuleDeclarationName::Identifier(ident) = &decl.id else { return };
|
||||
let Some(TSModuleDeclarationBody::TSModuleBlock(block)) = &decl.body else { return };
|
||||
let ident = &decl.id;
|
||||
let TSNamespaceDeclarationBody::TSModuleBlock(block) = &decl.body else { return };
|
||||
for stmt in &block.body {
|
||||
let Statement::ExportDeclaration(decl) = stmt else { continue };
|
||||
match &decl.declaration {
|
||||
@@ -595,7 +591,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
Declaration::TSModuleDeclaration(decl) => {
|
||||
Declaration::TSNamespaceDeclaration(decl) => {
|
||||
Self::collect_namespace_properties(
|
||||
decl,
|
||||
&mut assignable_properties_for_namespace,
|
||||
@@ -631,7 +627,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
Statement::TSModuleDeclaration(decl) => {
|
||||
Statement::TSNamespaceDeclaration(decl) => {
|
||||
Self::collect_namespace_properties(
|
||||
decl,
|
||||
&mut assignable_properties_for_namespace,
|
||||
|
||||
@@ -199,10 +199,11 @@ impl<'a> Visit<'a> for ScopeTree<'a> {
|
||||
Declaration::TSEnumDeclaration(decl) => {
|
||||
self.add_binding(decl.id.name.into(), KindFlags::All);
|
||||
}
|
||||
Declaration::TSModuleDeclaration(decl) => {
|
||||
if let TSModuleDeclarationName::Identifier(ident) = &decl.id {
|
||||
self.add_binding(ident.name.into(), KindFlags::All);
|
||||
}
|
||||
Declaration::TSExternalModuleDeclaration(_) => {
|
||||
// no binding
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(decl) => {
|
||||
self.add_binding(decl.id.name.into(), KindFlags::All);
|
||||
}
|
||||
Declaration::TSGlobalDeclaration(_) => {
|
||||
// no binding
|
||||
|
||||
@@ -665,7 +665,8 @@ fn could_be_error_impl(
|
||||
}
|
||||
AstKind::Function(_)
|
||||
| AstKind::Class(_)
|
||||
| AstKind::TSModuleDeclaration(_)
|
||||
| AstKind::TSExternalModuleDeclaration(_)
|
||||
| AstKind::TSNamespaceDeclaration(_)
|
||||
| AstKind::TSGlobalDeclaration(_)
|
||||
| AstKind::TSEnumDeclaration(_) => false,
|
||||
AstKind::FormalParameter(param) => !param
|
||||
|
||||
+2
-2
@@ -1808,7 +1808,7 @@ impl RuleRunner for crate::rules::typescript::no_mixed_enums::NoMixedEnums {
|
||||
|
||||
impl RuleRunner for crate::rules::typescript::no_namespace::NoNamespace {
|
||||
const NODE_TYPES: Option<&AstTypesBitset> =
|
||||
Some(&AstTypesBitset::from_types(&[AstType::TSModuleDeclaration]));
|
||||
Some(&AstTypesBitset::from_types(&[AstType::TSNamespaceDeclaration]));
|
||||
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
|
||||
}
|
||||
|
||||
@@ -2087,7 +2087,7 @@ impl RuleRunner for crate::rules::typescript::prefer_literal_enum_member::Prefer
|
||||
|
||||
impl RuleRunner for crate::rules::typescript::prefer_namespace_keyword::PreferNamespaceKeyword {
|
||||
const NODE_TYPES: Option<&AstTypesBitset> =
|
||||
Some(&AstTypesBitset::from_types(&[AstType::TSModuleDeclaration]));
|
||||
Some(&AstTypesBitset::from_types(&[AstType::TSNamespaceDeclaration]));
|
||||
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use javascript_globals::GLOBALS;
|
||||
use oxc_allocator::GetAddress;
|
||||
use oxc_ast::{
|
||||
AstKind,
|
||||
ast::{BindingPattern, Expression, FunctionType, TSModuleDeclarationName},
|
||||
ast::{BindingPattern, Expression, FunctionType},
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
@@ -386,7 +386,10 @@ impl NoShadow {
|
||||
}
|
||||
AstKind::Class(class) if class.declare => return true,
|
||||
AstKind::TSEnumDeclaration(declaration) if declaration.declare => return true,
|
||||
AstKind::TSModuleDeclaration(declaration) if declaration.declare => return true,
|
||||
AstKind::TSExternalModuleDeclaration(declaration) if declaration.declare => {
|
||||
return true;
|
||||
}
|
||||
AstKind::TSNamespaceDeclaration(declaration) if declaration.declare => return true,
|
||||
AstKind::TSInterfaceDeclaration(declaration) if declaration.declare => return true,
|
||||
AstKind::TSTypeAliasDeclaration(declaration) if declaration.declare => return true,
|
||||
AstKind::Program(_) => break,
|
||||
@@ -401,13 +404,8 @@ impl NoShadow {
|
||||
let declaration_id = ctx.scoping().symbol_declaration(symbol_id);
|
||||
ctx.nodes().ancestor_kinds(declaration_id).any(|ancestor_kind| match ancestor_kind {
|
||||
AstKind::TSGlobalDeclaration(_) => true,
|
||||
AstKind::TSModuleDeclaration(module) => {
|
||||
module.declare
|
||||
&& matches!(
|
||||
&module.id,
|
||||
TSModuleDeclarationName::Identifier(identifier)
|
||||
if identifier.name.as_str() == "global"
|
||||
)
|
||||
AstKind::TSNamespaceDeclaration(module) => {
|
||||
module.declare && module.id.name.as_str() == "global"
|
||||
}
|
||||
_ => false,
|
||||
})
|
||||
@@ -471,15 +469,10 @@ impl NoShadow {
|
||||
|
||||
let declaration_id = ctx.scoping().symbol_declaration(symbol_id);
|
||||
let module_name = ctx.nodes().ancestor_kinds(declaration_id).find_map(|kind| {
|
||||
if let AstKind::TSModuleDeclaration(module_decl) = kind
|
||||
if let AstKind::TSExternalModuleDeclaration(module_decl) = kind
|
||||
&& module_decl.declare
|
||||
{
|
||||
match &module_decl.id {
|
||||
TSModuleDeclarationName::StringLiteral(string_literal) => {
|
||||
Some(string_literal.value.as_str())
|
||||
}
|
||||
TSModuleDeclarationName::Identifier(_) => None,
|
||||
}
|
||||
Some(module_decl.id.value.as_str())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -79,7 +79,9 @@ impl Rule for NoUnassignedVars {
|
||||
if ctx.nodes().ancestors(node.id()).skip(1).any(|ancestor| {
|
||||
matches!(
|
||||
ancestor.kind(),
|
||||
AstKind::TSModuleDeclaration(_) | AstKind::TSGlobalDeclaration(_)
|
||||
AstKind::TSExternalModuleDeclaration(_)
|
||||
| AstKind::TSNamespaceDeclaration(_)
|
||||
| AstKind::TSGlobalDeclaration(_)
|
||||
)
|
||||
}) {
|
||||
return;
|
||||
|
||||
@@ -75,7 +75,10 @@ impl Symbol<'_, '_> {
|
||||
.map(|scope_id| scopes.get_node_id(scope_id))
|
||||
.map(|node_id| nodes.get_node(node_id))
|
||||
.any(|node| match node.kind() {
|
||||
AstKind::TSModuleDeclaration(namespace) => {
|
||||
AstKind::TSExternalModuleDeclaration(module) => {
|
||||
is_ambient_external_module_without_explicit_exports(module)
|
||||
}
|
||||
AstKind::TSNamespaceDeclaration(namespace) => {
|
||||
is_ambient_namespace_without_explicit_exports(namespace)
|
||||
}
|
||||
// No need to check `declare` field, as `global` is only valid in ambient context
|
||||
@@ -86,33 +89,41 @@ impl Symbol<'_, '_> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_ambient_namespace_without_explicit_exports(namespace: &TSModuleDeclaration) -> bool {
|
||||
fn is_ambient_external_module_without_explicit_exports(
|
||||
module: &TSExternalModuleDeclaration,
|
||||
) -> bool {
|
||||
// Must be declared (ambient context)
|
||||
if !module.declare {
|
||||
return false;
|
||||
}
|
||||
|
||||
module.body.as_ref().is_none_or(|block| !has_explicit_exports(block))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_ambient_namespace_without_explicit_exports(namespace: &TSNamespaceDeclaration) -> bool {
|
||||
if !namespace.declare {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the module has explicit exports, unused types should still be checked
|
||||
// For modules with string literal names (like `declare module 'foo'`), if they have
|
||||
// an export statement, then only exported items are available externally
|
||||
if let Some(TSModuleDeclarationBody::TSModuleBlock(block)) = &namespace.body {
|
||||
let has_export = block.body.iter().any(|stmt| {
|
||||
matches!(
|
||||
stmt,
|
||||
Statement::ExportAllDeclaration(_)
|
||||
| Statement::ExportDefaultDeclaration(_)
|
||||
| Statement::ExportDeclaration(_)
|
||||
| Statement::ExportNamedDeclaration(_)
|
||||
| Statement::ExportFromDeclaration(_)
|
||||
| Statement::TSExportAssignment(_)
|
||||
)
|
||||
});
|
||||
if has_export {
|
||||
return false;
|
||||
}
|
||||
match &namespace.body {
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(_) => true,
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => !has_explicit_exports(block),
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
fn has_explicit_exports(block: &TSModuleBlock) -> bool {
|
||||
block.body.iter().any(|stmt| {
|
||||
matches!(
|
||||
stmt,
|
||||
Statement::ExportAllDeclaration(_)
|
||||
| Statement::ExportDefaultDeclaration(_)
|
||||
| Statement::ExportDeclaration(_)
|
||||
| Statement::ExportNamedDeclaration(_)
|
||||
| Statement::ExportFromDeclaration(_)
|
||||
| Statement::TSExportAssignment(_)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) enum FunctionParameterKind<'a> {
|
||||
@@ -134,17 +145,17 @@ impl NoUnusedVars {
|
||||
pub(super) fn is_allowed_ts_namespace<'a>(
|
||||
&self,
|
||||
symbol: &Symbol<'_, 'a>,
|
||||
namespace: &TSModuleDeclaration<'a>,
|
||||
namespace: &TSNamespaceDeclaration<'a>,
|
||||
) -> bool {
|
||||
if namespace.declare || symbol.is_in_declared_module() {
|
||||
return true;
|
||||
}
|
||||
// Segments of a dotted namespace declaration (`namespace A.B.C {}`) are
|
||||
// parsed as nested `TSModuleDeclaration`s. Don't flag any segment as unused.
|
||||
matches!(&namespace.body, Some(TSModuleDeclarationBody::TSModuleDeclaration(_)))
|
||||
// parsed as nested `TSNamespaceDeclaration`s. Don't flag any segment as unused.
|
||||
matches!(&namespace.body, TSNamespaceDeclarationBody::TSNamespaceDeclaration(_))
|
||||
|| matches!(
|
||||
symbol.nodes().parent_kind(symbol.declaration().id()),
|
||||
AstKind::TSModuleDeclaration(_)
|
||||
AstKind::TSNamespaceDeclaration(_)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -208,8 +219,10 @@ impl NoUnusedVars {
|
||||
if scope_flags.is_ts_module_block() {
|
||||
// get declaration node for the parent scope
|
||||
let parent_node_id = scoping.get_node_id(parent_scope_id);
|
||||
if let AstKind::TSModuleDeclaration(namespace) = nodes.get_node(parent_node_id).kind() {
|
||||
return namespace.declare;
|
||||
match nodes.get_node(parent_node_id).kind() {
|
||||
AstKind::TSExternalModuleDeclaration(module) => return module.declare,
|
||||
AstKind::TSNamespaceDeclaration(namespace) => return namespace.declare,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ impl NoUnusedVars {
|
||||
| AstKind::TSImportEqualsDeclaration(_)
|
||||
| AstKind::TSInterfaceDeclaration(_)
|
||||
| AstKind::TSMappedType(_)
|
||||
| AstKind::TSModuleDeclaration(_)
|
||||
| AstKind::TSNamespaceDeclaration(_)
|
||||
| AstKind::TSTypeAliasDeclaration(_)
|
||||
| AstKind::TSTypeParameter(_) => self.is_ignored_var(declared_binding),
|
||||
AstKind::Function(func) => {
|
||||
|
||||
@@ -366,7 +366,7 @@ impl NoUnusedVars {
|
||||
}
|
||||
ctx.diagnostic(diagnostic::declared(symbol, &self.vars_ignore_pattern, false));
|
||||
}
|
||||
AstKind::TSModuleDeclaration(namespace) => {
|
||||
AstKind::TSNamespaceDeclaration(namespace) => {
|
||||
if self.is_allowed_ts_namespace(symbol, namespace) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -314,7 +314,8 @@ impl<'a> Symbol<'_, 'a> {
|
||||
// e.g.:
|
||||
// - `type Foo = { bar(): Foo }`
|
||||
// - `class Foo { static factory(): Foo { return new Foo() } }`
|
||||
AstKind::TSModuleDeclaration(_)
|
||||
AstKind::TSExternalModuleDeclaration(_)
|
||||
| AstKind::TSNamespaceDeclaration(_)
|
||||
| AstKind::TSGlobalDeclaration(_)
|
||||
| AstKind::VariableDeclaration(_)
|
||||
| AstKind::VariableDeclarator(_)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use oxc_ast::{AstKind, ast::TSModuleDeclarationName};
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::Span;
|
||||
@@ -124,16 +124,13 @@ impl Rule for NoNamespace {
|
||||
}
|
||||
|
||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
let AstKind::TSModuleDeclaration(declaration) = node.kind() else {
|
||||
let AstKind::TSNamespaceDeclaration(declaration) = node.kind() else {
|
||||
return;
|
||||
};
|
||||
if !matches!(&declaration.id, TSModuleDeclarationName::Identifier(_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore nested `TSModuleDeclaration`s
|
||||
// e.g. the 2 inner `TSModuleDeclaration`s in `module A.B.C {}`
|
||||
if let AstKind::TSModuleDeclaration(_) = ctx.nodes().parent_kind(node.id()) {
|
||||
// Ignore nested `TSNamespaceDeclaration`s
|
||||
// e.g. the 2 inner declarations in `module A.B.C {}`
|
||||
if let AstKind::TSNamespaceDeclaration(_) = ctx.nodes().parent_kind(node.id()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
use oxc_ast::{
|
||||
AstKind,
|
||||
ast::{TSModuleDeclaration, TSModuleDeclarationKind, TSModuleDeclarationName},
|
||||
};
|
||||
use oxc_ast::{AstKind, ast::TSNamespaceDeclarationKind};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::Span;
|
||||
@@ -66,22 +63,17 @@ declare_oxc_lint!(
|
||||
short_description = "Require using `namespace` keyword over `module` keyword to declare custom TypeScript modules.",
|
||||
);
|
||||
|
||||
fn is_valid_module(module: &TSModuleDeclaration) -> bool {
|
||||
matches!(module.id, TSModuleDeclarationName::Identifier(_))
|
||||
&& module.kind == TSModuleDeclarationKind::Module
|
||||
}
|
||||
|
||||
impl Rule for PreferNamespaceKeyword {
|
||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
let AstKind::TSModuleDeclaration(module) = node.kind() else { return };
|
||||
let AstKind::TSNamespaceDeclaration(module) = node.kind() else { return };
|
||||
|
||||
if !is_valid_module(module) {
|
||||
if module.kind != TSNamespaceDeclarationKind::Module {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore nested `TSModuleDeclaration`s
|
||||
// e.g. the 2 inner `TSModuleDeclaration`s in `module A.B.C {}`
|
||||
if let AstKind::TSModuleDeclaration(_) = ctx.nodes().parent_kind(node.id()) {
|
||||
// Ignore nested `TSNamespaceDeclaration`s
|
||||
// e.g. the 2 inner declarations in `module A.B.C {}`
|
||||
if let AstKind::TSNamespaceDeclaration(_) = ctx.nodes().parent_kind(node.id()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,8 @@ pub enum NameSpecifier {
|
||||
/// including `global {}` nested inside ambient modules or namespaces.
|
||||
pub fn has_ambient_typescript_ancestor(node_id: NodeId, nodes: &AstNodes) -> bool {
|
||||
nodes.ancestors(node_id).any(|ancestor| match ancestor.kind() {
|
||||
AstKind::TSModuleDeclaration(module) => module.declare,
|
||||
AstKind::TSExternalModuleDeclaration(module) => module.declare,
|
||||
AstKind::TSNamespaceDeclaration(namespace) => namespace.declare,
|
||||
// `TSGlobalDeclaration`s are only valid inside ambient declarations, hence
|
||||
// we do not need to check `declare` as it only tracks an explicit `declare global`.
|
||||
AstKind::TSGlobalDeclaration(_) => true,
|
||||
|
||||
@@ -277,51 +277,53 @@ pub(crate) enum AncestorType {
|
||||
TSInterfaceHeritageTypeArguments = 253,
|
||||
TSTypePredicateParameterName = 254,
|
||||
TSTypePredicateTypeAnnotation = 255,
|
||||
TSModuleDeclarationId = 256,
|
||||
TSModuleDeclarationBody = 257,
|
||||
TSGlobalDeclarationBody = 258,
|
||||
TSModuleBlockDirectives = 259,
|
||||
TSModuleBlockBody = 260,
|
||||
TSTypeLiteralMembers = 261,
|
||||
TSInferTypeTypeParameter = 262,
|
||||
TSTypeQueryExprName = 263,
|
||||
TSTypeQueryTypeArguments = 264,
|
||||
TSImportTypeSource = 265,
|
||||
TSImportTypeOptions = 266,
|
||||
TSImportTypeQualifier = 267,
|
||||
TSImportTypeTypeArguments = 268,
|
||||
TSImportTypeQualifiedNameLeft = 269,
|
||||
TSImportTypeQualifiedNameRight = 270,
|
||||
TSFunctionTypeTypeParameters = 271,
|
||||
TSFunctionTypeThisParam = 272,
|
||||
TSFunctionTypeParams = 273,
|
||||
TSFunctionTypeReturnType = 274,
|
||||
TSConstructorTypeTypeParameters = 275,
|
||||
TSConstructorTypeParams = 276,
|
||||
TSConstructorTypeReturnType = 277,
|
||||
TSMappedTypeKey = 278,
|
||||
TSMappedTypeConstraint = 279,
|
||||
TSMappedTypeNameType = 280,
|
||||
TSMappedTypeTypeAnnotation = 281,
|
||||
TSTemplateLiteralTypeQuasis = 282,
|
||||
TSTemplateLiteralTypeTypes = 283,
|
||||
TSAsExpressionExpression = 284,
|
||||
TSAsExpressionTypeAnnotation = 285,
|
||||
TSSatisfiesExpressionExpression = 286,
|
||||
TSSatisfiesExpressionTypeAnnotation = 287,
|
||||
TSTypeAssertionTypeAnnotation = 288,
|
||||
TSTypeAssertionExpression = 289,
|
||||
TSImportEqualsDeclarationId = 290,
|
||||
TSImportEqualsDeclarationModuleReference = 291,
|
||||
TSExternalModuleReferenceExpression = 292,
|
||||
TSNonNullExpressionExpression = 293,
|
||||
DecoratorExpression = 294,
|
||||
TSExportAssignmentExpression = 295,
|
||||
TSNamespaceExportDeclarationId = 296,
|
||||
TSInstantiationExpressionExpression = 297,
|
||||
TSInstantiationExpressionTypeArguments = 298,
|
||||
JSDocNullableTypeTypeAnnotation = 299,
|
||||
JSDocNonNullableTypeTypeAnnotation = 300,
|
||||
TSExternalModuleDeclarationId = 256,
|
||||
TSExternalModuleDeclarationBody = 257,
|
||||
TSNamespaceDeclarationId = 258,
|
||||
TSNamespaceDeclarationBody = 259,
|
||||
TSGlobalDeclarationBody = 260,
|
||||
TSModuleBlockDirectives = 261,
|
||||
TSModuleBlockBody = 262,
|
||||
TSTypeLiteralMembers = 263,
|
||||
TSInferTypeTypeParameter = 264,
|
||||
TSTypeQueryExprName = 265,
|
||||
TSTypeQueryTypeArguments = 266,
|
||||
TSImportTypeSource = 267,
|
||||
TSImportTypeOptions = 268,
|
||||
TSImportTypeQualifier = 269,
|
||||
TSImportTypeTypeArguments = 270,
|
||||
TSImportTypeQualifiedNameLeft = 271,
|
||||
TSImportTypeQualifiedNameRight = 272,
|
||||
TSFunctionTypeTypeParameters = 273,
|
||||
TSFunctionTypeThisParam = 274,
|
||||
TSFunctionTypeParams = 275,
|
||||
TSFunctionTypeReturnType = 276,
|
||||
TSConstructorTypeTypeParameters = 277,
|
||||
TSConstructorTypeParams = 278,
|
||||
TSConstructorTypeReturnType = 279,
|
||||
TSMappedTypeKey = 280,
|
||||
TSMappedTypeConstraint = 281,
|
||||
TSMappedTypeNameType = 282,
|
||||
TSMappedTypeTypeAnnotation = 283,
|
||||
TSTemplateLiteralTypeQuasis = 284,
|
||||
TSTemplateLiteralTypeTypes = 285,
|
||||
TSAsExpressionExpression = 286,
|
||||
TSAsExpressionTypeAnnotation = 287,
|
||||
TSSatisfiesExpressionExpression = 288,
|
||||
TSSatisfiesExpressionTypeAnnotation = 289,
|
||||
TSTypeAssertionTypeAnnotation = 290,
|
||||
TSTypeAssertionExpression = 291,
|
||||
TSImportEqualsDeclarationId = 292,
|
||||
TSImportEqualsDeclarationModuleReference = 293,
|
||||
TSExternalModuleReferenceExpression = 294,
|
||||
TSNonNullExpressionExpression = 295,
|
||||
DecoratorExpression = 296,
|
||||
TSExportAssignmentExpression = 297,
|
||||
TSNamespaceExportDeclarationId = 298,
|
||||
TSInstantiationExpressionExpression = 299,
|
||||
TSInstantiationExpressionTypeArguments = 300,
|
||||
JSDocNullableTypeTypeAnnotation = 301,
|
||||
JSDocNonNullableTypeTypeAnnotation = 302,
|
||||
}
|
||||
|
||||
/// Ancestor type used in AST traversal.
|
||||
@@ -817,10 +819,14 @@ pub enum Ancestor<'a, 't> {
|
||||
AncestorType::TSTypePredicateParameterName as u16,
|
||||
TSTypePredicateTypeAnnotation(TSTypePredicateWithoutTypeAnnotation<'a, 't>) =
|
||||
AncestorType::TSTypePredicateTypeAnnotation as u16,
|
||||
TSModuleDeclarationId(TSModuleDeclarationWithoutId<'a, 't>) =
|
||||
AncestorType::TSModuleDeclarationId as u16,
|
||||
TSModuleDeclarationBody(TSModuleDeclarationWithoutBody<'a, 't>) =
|
||||
AncestorType::TSModuleDeclarationBody as u16,
|
||||
TSExternalModuleDeclarationId(TSExternalModuleDeclarationWithoutId<'a, 't>) =
|
||||
AncestorType::TSExternalModuleDeclarationId as u16,
|
||||
TSExternalModuleDeclarationBody(TSExternalModuleDeclarationWithoutBody<'a, 't>) =
|
||||
AncestorType::TSExternalModuleDeclarationBody as u16,
|
||||
TSNamespaceDeclarationId(TSNamespaceDeclarationWithoutId<'a, 't>) =
|
||||
AncestorType::TSNamespaceDeclarationId as u16,
|
||||
TSNamespaceDeclarationBody(TSNamespaceDeclarationWithoutBody<'a, 't>) =
|
||||
AncestorType::TSNamespaceDeclarationBody as u16,
|
||||
TSGlobalDeclarationBody(TSGlobalDeclarationWithoutBody<'a, 't>) =
|
||||
AncestorType::TSGlobalDeclarationBody as u16,
|
||||
TSModuleBlockDirectives(TSModuleBlockWithoutDirectives<'a, 't>) =
|
||||
@@ -1748,8 +1754,16 @@ impl<'a, 't> Ancestor<'a, 't> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_ts_module_declaration(self) -> bool {
|
||||
matches!(self, Self::TSModuleDeclarationId(_) | Self::TSModuleDeclarationBody(_))
|
||||
pub fn is_ts_external_module_declaration(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::TSExternalModuleDeclarationId(_) | Self::TSExternalModuleDeclarationBody(_)
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_ts_namespace_declaration(self) -> bool {
|
||||
matches!(self, Self::TSNamespaceDeclarationId(_) | Self::TSNamespaceDeclarationBody(_))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -2230,13 +2244,8 @@ impl<'a, 't> Ancestor<'a, 't> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_parent_of_ts_module_declaration_name(self) -> bool {
|
||||
matches!(self, Self::TSModuleDeclarationId(_))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_parent_of_ts_module_declaration_body(self) -> bool {
|
||||
matches!(self, Self::TSModuleDeclarationBody(_))
|
||||
pub fn is_parent_of_ts_namespace_declaration_body(self) -> bool {
|
||||
matches!(self, Self::TSNamespaceDeclarationBody(_))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -2517,8 +2526,10 @@ impl<'a, 't> GetAddress for Ancestor<'a, 't> {
|
||||
Self::TSInterfaceHeritageTypeArguments(a) => a.address(),
|
||||
Self::TSTypePredicateParameterName(a) => a.address(),
|
||||
Self::TSTypePredicateTypeAnnotation(a) => a.address(),
|
||||
Self::TSModuleDeclarationId(a) => a.address(),
|
||||
Self::TSModuleDeclarationBody(a) => a.address(),
|
||||
Self::TSExternalModuleDeclarationId(a) => a.address(),
|
||||
Self::TSExternalModuleDeclarationBody(a) => a.address(),
|
||||
Self::TSNamespaceDeclarationId(a) => a.address(),
|
||||
Self::TSNamespaceDeclarationBody(a) => a.address(),
|
||||
Self::TSGlobalDeclarationBody(a) => a.address(),
|
||||
Self::TSModuleBlockDirectives(a) => a.address(),
|
||||
Self::TSModuleBlockBody(a) => a.address(),
|
||||
@@ -16245,71 +16256,68 @@ impl<'a, 't> GetAddress for TSTypePredicateWithoutTypeAnnotation<'a, 't> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_NODE_ID: usize =
|
||||
offset_of!(TSModuleDeclaration, node_id);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_SPAN: usize = offset_of!(TSModuleDeclaration, span);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_ID: usize = offset_of!(TSModuleDeclaration, id);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_BODY: usize = offset_of!(TSModuleDeclaration, body);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_KIND: usize = offset_of!(TSModuleDeclaration, kind);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_DECLARE: usize =
|
||||
offset_of!(TSModuleDeclaration, declare);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_SCOPE_ID: usize =
|
||||
offset_of!(TSModuleDeclaration, scope_id);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_NODE_ID: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, node_id);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SPAN: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, span);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_ID: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, id);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_BODY: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, body);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_DECLARE: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, declare);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SCOPE_ID: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, scope_id);
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TSModuleDeclarationWithoutId<'a, 't>(
|
||||
pub(crate) *const TSModuleDeclaration<'a>,
|
||||
pub struct TSExternalModuleDeclarationWithoutId<'a, 't>(
|
||||
pub(crate) *const TSExternalModuleDeclaration<'a>,
|
||||
pub(crate) PhantomData<&'t ()>,
|
||||
);
|
||||
|
||||
impl<'a, 't> TSModuleDeclarationWithoutId<'a, 't> {
|
||||
impl<'a, 't> TSExternalModuleDeclarationWithoutId<'a, 't> {
|
||||
#[inline]
|
||||
pub fn node_id(self) -> &'t Cell<NodeId> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_NODE_ID)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_NODE_ID)
|
||||
as *const Cell<NodeId>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(self) -> &'t Span {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_SPAN) as *const Span) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn body(self) -> &'t Option<TSModuleDeclarationBody<'a>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_BODY)
|
||||
as *const Option<TSModuleDeclarationBody<'a>>)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SPAN) as *const Span)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(self) -> &'t TSModuleDeclarationKind {
|
||||
pub fn body(self) -> &'t Option<ArenaBox<'a, TSModuleBlock<'a>>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_KIND)
|
||||
as *const TSModuleDeclarationKind)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_BODY)
|
||||
as *const Option<ArenaBox<'a, TSModuleBlock<'a>>>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn declare(self) -> &'t bool {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_DECLARE) as *const bool)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_DECLARE)
|
||||
as *const bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_SCOPE_ID)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SCOPE_ID)
|
||||
as *const Cell<Option<ScopeId>>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 't> GetAddress for TSModuleDeclarationWithoutId<'a, 't> {
|
||||
impl<'a, 't> GetAddress for TSExternalModuleDeclarationWithoutId<'a, 't> {
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
unsafe { Address::from_ptr(self.0) }
|
||||
@@ -16318,58 +16326,191 @@ impl<'a, 't> GetAddress for TSModuleDeclarationWithoutId<'a, 't> {
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TSModuleDeclarationWithoutBody<'a, 't>(
|
||||
pub(crate) *const TSModuleDeclaration<'a>,
|
||||
pub struct TSExternalModuleDeclarationWithoutBody<'a, 't>(
|
||||
pub(crate) *const TSExternalModuleDeclaration<'a>,
|
||||
pub(crate) PhantomData<&'t ()>,
|
||||
);
|
||||
|
||||
impl<'a, 't> TSModuleDeclarationWithoutBody<'a, 't> {
|
||||
impl<'a, 't> TSExternalModuleDeclarationWithoutBody<'a, 't> {
|
||||
#[inline]
|
||||
pub fn node_id(self) -> &'t Cell<NodeId> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_NODE_ID)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_NODE_ID)
|
||||
as *const Cell<NodeId>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(self) -> &'t Span {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_SPAN) as *const Span) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(self) -> &'t TSModuleDeclarationName<'a> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_ID)
|
||||
as *const TSModuleDeclarationName<'a>)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SPAN) as *const Span)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(self) -> &'t TSModuleDeclarationKind {
|
||||
pub fn id(self) -> &'t StringLiteral<'a> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_KIND)
|
||||
as *const TSModuleDeclarationKind)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_ID)
|
||||
as *const StringLiteral<'a>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn declare(self) -> &'t bool {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_DECLARE) as *const bool)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_DECLARE)
|
||||
as *const bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_SCOPE_ID)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SCOPE_ID)
|
||||
as *const Cell<Option<ScopeId>>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 't> GetAddress for TSModuleDeclarationWithoutBody<'a, 't> {
|
||||
impl<'a, 't> GetAddress for TSExternalModuleDeclarationWithoutBody<'a, 't> {
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
unsafe { Address::from_ptr(self.0) }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_NODE_ID: usize =
|
||||
offset_of!(TSNamespaceDeclaration, node_id);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_SPAN: usize =
|
||||
offset_of!(TSNamespaceDeclaration, span);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_ID: usize = offset_of!(TSNamespaceDeclaration, id);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_BODY: usize =
|
||||
offset_of!(TSNamespaceDeclaration, body);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_KIND: usize =
|
||||
offset_of!(TSNamespaceDeclaration, kind);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_DECLARE: usize =
|
||||
offset_of!(TSNamespaceDeclaration, declare);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_SCOPE_ID: usize =
|
||||
offset_of!(TSNamespaceDeclaration, scope_id);
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TSNamespaceDeclarationWithoutId<'a, 't>(
|
||||
pub(crate) *const TSNamespaceDeclaration<'a>,
|
||||
pub(crate) PhantomData<&'t ()>,
|
||||
);
|
||||
|
||||
impl<'a, 't> TSNamespaceDeclarationWithoutId<'a, 't> {
|
||||
#[inline]
|
||||
pub fn node_id(self) -> &'t Cell<NodeId> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_NODE_ID)
|
||||
as *const Cell<NodeId>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(self) -> &'t Span {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_SPAN) as *const Span)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn body(self) -> &'t TSNamespaceDeclarationBody<'a> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_BODY)
|
||||
as *const TSNamespaceDeclarationBody<'a>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(self) -> &'t TSNamespaceDeclarationKind {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_KIND)
|
||||
as *const TSNamespaceDeclarationKind)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn declare(self) -> &'t bool {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_DECLARE) as *const bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_SCOPE_ID)
|
||||
as *const Cell<Option<ScopeId>>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 't> GetAddress for TSNamespaceDeclarationWithoutId<'a, 't> {
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
unsafe { Address::from_ptr(self.0) }
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TSNamespaceDeclarationWithoutBody<'a, 't>(
|
||||
pub(crate) *const TSNamespaceDeclaration<'a>,
|
||||
pub(crate) PhantomData<&'t ()>,
|
||||
);
|
||||
|
||||
impl<'a, 't> TSNamespaceDeclarationWithoutBody<'a, 't> {
|
||||
#[inline]
|
||||
pub fn node_id(self) -> &'t Cell<NodeId> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_NODE_ID)
|
||||
as *const Cell<NodeId>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(self) -> &'t Span {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_SPAN) as *const Span)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(self) -> &'t BindingIdentifier<'a> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_ID)
|
||||
as *const BindingIdentifier<'a>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(self) -> &'t TSNamespaceDeclarationKind {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_KIND)
|
||||
as *const TSNamespaceDeclarationKind)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn declare(self) -> &'t bool {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_DECLARE) as *const bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_SCOPE_ID)
|
||||
as *const Cell<Option<ScopeId>>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 't> GetAddress for TSNamespaceDeclarationWithoutBody<'a, 't> {
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
unsafe { Address::from_ptr(self.0) }
|
||||
|
||||
@@ -2174,46 +2174,46 @@ pub trait Traverse<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn enter_ts_module_declaration(
|
||||
fn enter_ts_external_module_declaration(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclaration<'a>,
|
||||
node: &mut TSExternalModuleDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
}
|
||||
#[inline]
|
||||
fn exit_ts_module_declaration(
|
||||
fn exit_ts_external_module_declaration(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclaration<'a>,
|
||||
node: &mut TSExternalModuleDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn enter_ts_module_declaration_name(
|
||||
fn enter_ts_namespace_declaration(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclarationName<'a>,
|
||||
node: &mut TSNamespaceDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
}
|
||||
#[inline]
|
||||
fn exit_ts_module_declaration_name(
|
||||
fn exit_ts_namespace_declaration(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclarationName<'a>,
|
||||
node: &mut TSNamespaceDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn enter_ts_module_declaration_body(
|
||||
fn enter_ts_namespace_declaration_body(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclarationBody<'a>,
|
||||
node: &mut TSNamespaceDeclarationBody<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
}
|
||||
#[inline]
|
||||
fn exit_ts_module_declaration_body(
|
||||
fn exit_ts_namespace_declaration_body(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclarationBody<'a>,
|
||||
node: &mut TSNamespaceDeclarationBody<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -1374,7 +1374,8 @@ unsafe fn walk_statement<'a, Tr: Traverse<'a>>(
|
||||
| Statement::TSTypeAliasDeclaration(_)
|
||||
| Statement::TSInterfaceDeclaration(_)
|
||||
| Statement::TSEnumDeclaration(_)
|
||||
| Statement::TSModuleDeclaration(_)
|
||||
| Statement::TSExternalModuleDeclaration(_)
|
||||
| Statement::TSNamespaceDeclaration(_)
|
||||
| Statement::TSGlobalDeclaration(_)
|
||||
| Statement::TSImportEqualsDeclaration(_) => {
|
||||
walk_declaration(traverser, node as *mut _, ctx)
|
||||
@@ -1471,8 +1472,11 @@ unsafe fn walk_declaration<'a, Tr: Traverse<'a>>(
|
||||
Declaration::TSEnumDeclaration(node) => {
|
||||
walk_ts_enum_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
Declaration::TSModuleDeclaration(node) => {
|
||||
walk_ts_module_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
Declaration::TSExternalModuleDeclaration(node) => {
|
||||
walk_ts_external_module_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(node) => {
|
||||
walk_ts_namespace_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
Declaration::TSGlobalDeclaration(node) => {
|
||||
walk_ts_global_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
@@ -5102,77 +5106,101 @@ unsafe fn walk_ts_type_predicate_name<'a, Tr: Traverse<'a>>(
|
||||
traverser.exit_ts_type_predicate_name(&mut *node, ctx);
|
||||
}
|
||||
|
||||
unsafe fn walk_ts_module_declaration<'a, Tr: Traverse<'a>>(
|
||||
unsafe fn walk_ts_external_module_declaration<'a, Tr: Traverse<'a>>(
|
||||
traverser: &mut Tr,
|
||||
node: *mut TSModuleDeclaration<'a>,
|
||||
node: *mut TSExternalModuleDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
traverser.enter_ts_module_declaration(&mut *node, ctx);
|
||||
let pop_token = ctx.push_stack(Ancestor::TSModuleDeclarationId(
|
||||
ancestor::TSModuleDeclarationWithoutId(node, PhantomData),
|
||||
traverser.enter_ts_external_module_declaration(&mut *node, ctx);
|
||||
let pop_token = ctx.push_stack(Ancestor::TSExternalModuleDeclarationId(
|
||||
ancestor::TSExternalModuleDeclarationWithoutId(node, PhantomData),
|
||||
));
|
||||
walk_ts_module_declaration_name(
|
||||
walk_string_literal(
|
||||
traverser,
|
||||
(node as *mut u8).add(ancestor::OFFSET_TS_MODULE_DECLARATION_ID)
|
||||
as *mut TSModuleDeclarationName,
|
||||
(node as *mut u8).add(ancestor::OFFSET_TS_EXTERNAL_MODULE_DECLARATION_ID)
|
||||
as *mut StringLiteral,
|
||||
ctx,
|
||||
);
|
||||
let previous_scope_id = ctx.current_scope_id();
|
||||
let current_scope_id =
|
||||
(*((node as *mut u8).add(ancestor::OFFSET_TS_MODULE_DECLARATION_SCOPE_ID)
|
||||
as *mut Cell<Option<ScopeId>>))
|
||||
.get()
|
||||
.unwrap();
|
||||
let current_scope_id = (*((node as *mut u8)
|
||||
.add(ancestor::OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SCOPE_ID)
|
||||
as *mut Cell<Option<ScopeId>>))
|
||||
.get()
|
||||
.unwrap();
|
||||
ctx.set_current_scope_id(current_scope_id);
|
||||
let previous_hoist_scope_id = ctx.current_hoist_scope_id();
|
||||
ctx.set_current_hoist_scope_id(current_scope_id);
|
||||
let previous_block_scope_id = ctx.current_block_scope_id();
|
||||
ctx.set_current_block_scope_id(current_scope_id);
|
||||
if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_TS_MODULE_DECLARATION_BODY)
|
||||
as *mut Option<TSModuleDeclarationBody>)
|
||||
if let Some(field) = &mut *((node as *mut u8)
|
||||
.add(ancestor::OFFSET_TS_EXTERNAL_MODULE_DECLARATION_BODY)
|
||||
as *mut Option<ArenaBox<TSModuleBlock>>)
|
||||
{
|
||||
ctx.retag_stack(AncestorType::TSModuleDeclarationBody);
|
||||
walk_ts_module_declaration_body(traverser, field as *mut _, ctx);
|
||||
ctx.retag_stack(AncestorType::TSExternalModuleDeclarationBody);
|
||||
walk_ts_module_block(traverser, (&mut **field) as *mut _, ctx);
|
||||
}
|
||||
ctx.pop_stack(pop_token);
|
||||
ctx.set_current_scope_id(previous_scope_id);
|
||||
ctx.set_current_hoist_scope_id(previous_hoist_scope_id);
|
||||
ctx.set_current_block_scope_id(previous_block_scope_id);
|
||||
traverser.exit_ts_module_declaration(&mut *node, ctx);
|
||||
traverser.exit_ts_external_module_declaration(&mut *node, ctx);
|
||||
}
|
||||
|
||||
unsafe fn walk_ts_module_declaration_name<'a, Tr: Traverse<'a>>(
|
||||
unsafe fn walk_ts_namespace_declaration<'a, Tr: Traverse<'a>>(
|
||||
traverser: &mut Tr,
|
||||
node: *mut TSModuleDeclarationName<'a>,
|
||||
node: *mut TSNamespaceDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
traverser.enter_ts_module_declaration_name(&mut *node, ctx);
|
||||
match &mut *node {
|
||||
TSModuleDeclarationName::Identifier(node) => {
|
||||
walk_binding_identifier(traverser, node as *mut _, ctx)
|
||||
}
|
||||
TSModuleDeclarationName::StringLiteral(node) => {
|
||||
walk_string_literal(traverser, node as *mut _, ctx)
|
||||
}
|
||||
}
|
||||
traverser.exit_ts_module_declaration_name(&mut *node, ctx);
|
||||
traverser.enter_ts_namespace_declaration(&mut *node, ctx);
|
||||
let pop_token = ctx.push_stack(Ancestor::TSNamespaceDeclarationId(
|
||||
ancestor::TSNamespaceDeclarationWithoutId(node, PhantomData),
|
||||
));
|
||||
walk_binding_identifier(
|
||||
traverser,
|
||||
(node as *mut u8).add(ancestor::OFFSET_TS_NAMESPACE_DECLARATION_ID)
|
||||
as *mut BindingIdentifier,
|
||||
ctx,
|
||||
);
|
||||
let previous_scope_id = ctx.current_scope_id();
|
||||
let current_scope_id = (*((node as *mut u8)
|
||||
.add(ancestor::OFFSET_TS_NAMESPACE_DECLARATION_SCOPE_ID)
|
||||
as *mut Cell<Option<ScopeId>>))
|
||||
.get()
|
||||
.unwrap();
|
||||
ctx.set_current_scope_id(current_scope_id);
|
||||
let previous_hoist_scope_id = ctx.current_hoist_scope_id();
|
||||
ctx.set_current_hoist_scope_id(current_scope_id);
|
||||
let previous_block_scope_id = ctx.current_block_scope_id();
|
||||
ctx.set_current_block_scope_id(current_scope_id);
|
||||
ctx.retag_stack(AncestorType::TSNamespaceDeclarationBody);
|
||||
walk_ts_namespace_declaration_body(
|
||||
traverser,
|
||||
(node as *mut u8).add(ancestor::OFFSET_TS_NAMESPACE_DECLARATION_BODY)
|
||||
as *mut TSNamespaceDeclarationBody,
|
||||
ctx,
|
||||
);
|
||||
ctx.pop_stack(pop_token);
|
||||
ctx.set_current_scope_id(previous_scope_id);
|
||||
ctx.set_current_hoist_scope_id(previous_hoist_scope_id);
|
||||
ctx.set_current_block_scope_id(previous_block_scope_id);
|
||||
traverser.exit_ts_namespace_declaration(&mut *node, ctx);
|
||||
}
|
||||
|
||||
unsafe fn walk_ts_module_declaration_body<'a, Tr: Traverse<'a>>(
|
||||
unsafe fn walk_ts_namespace_declaration_body<'a, Tr: Traverse<'a>>(
|
||||
traverser: &mut Tr,
|
||||
node: *mut TSModuleDeclarationBody<'a>,
|
||||
node: *mut TSNamespaceDeclarationBody<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
traverser.enter_ts_module_declaration_body(&mut *node, ctx);
|
||||
traverser.enter_ts_namespace_declaration_body(&mut *node, ctx);
|
||||
match &mut *node {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(node) => {
|
||||
walk_ts_module_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(node) => {
|
||||
walk_ts_namespace_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(node) => {
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(node) => {
|
||||
walk_ts_module_block(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
}
|
||||
traverser.exit_ts_module_declaration_body(&mut *node, ctx);
|
||||
traverser.exit_ts_namespace_declaration_body(&mut *node, ctx);
|
||||
}
|
||||
|
||||
unsafe fn walk_ts_global_declaration<'a, Tr: Traverse<'a>>(
|
||||
|
||||
@@ -623,7 +623,10 @@ impl<'a> Visit<'a> for ChildScopeCollector {
|
||||
Statement::TSTypeAliasDeclaration(it) => self.visit_ts_type_alias_declaration(it),
|
||||
Statement::TSInterfaceDeclaration(it) => self.visit_ts_interface_declaration(it),
|
||||
Statement::TSEnumDeclaration(it) => self.visit_ts_enum_declaration(it),
|
||||
Statement::TSModuleDeclaration(it) => self.visit_ts_module_declaration(it),
|
||||
Statement::TSExternalModuleDeclaration(it) => {
|
||||
self.visit_ts_external_module_declaration(it)
|
||||
}
|
||||
Statement::TSNamespaceDeclaration(it) => self.visit_ts_namespace_declaration(it),
|
||||
Statement::TSGlobalDeclaration(it) => self.visit_ts_global_declaration(it),
|
||||
Statement::ExportDefaultDeclaration(it) => self.visit_export_default_declaration(it),
|
||||
Statement::ExportDeclaration(it) => self.visit_export_declaration(it),
|
||||
@@ -670,7 +673,10 @@ impl<'a> Visit<'a> for ChildScopeCollector {
|
||||
Declaration::TSTypeAliasDeclaration(it) => self.visit_ts_type_alias_declaration(it),
|
||||
Declaration::TSInterfaceDeclaration(it) => self.visit_ts_interface_declaration(it),
|
||||
Declaration::TSEnumDeclaration(it) => self.visit_ts_enum_declaration(it),
|
||||
Declaration::TSModuleDeclaration(it) => self.visit_ts_module_declaration(it),
|
||||
Declaration::TSExternalModuleDeclaration(it) => {
|
||||
self.visit_ts_external_module_declaration(it)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(it) => self.visit_ts_namespace_declaration(it),
|
||||
Declaration::TSGlobalDeclaration(it) => self.visit_ts_global_declaration(it),
|
||||
_ => {
|
||||
// Remaining variants do not contain scopes:
|
||||
@@ -1948,13 +1954,13 @@ impl<'a> Visit<'a> for ChildScopeCollector {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration(&mut self, it: &TSModuleDeclaration<'a>) {
|
||||
fn visit_ts_external_module_declaration(&mut self, it: &TSExternalModuleDeclaration<'a>) {
|
||||
self.add_scope(&it.scope_id);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn visit_ts_module_declaration_name(&mut self, it: &TSModuleDeclarationName<'a>) {
|
||||
// Enum does not contain a scope. Halt traversal.
|
||||
#[inline]
|
||||
fn visit_ts_namespace_declaration(&mut self, it: &TSNamespaceDeclaration<'a>) {
|
||||
self.add_scope(&it.scope_id);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -936,7 +936,9 @@ impl<'a, C: ParserConfig> GetAstBuilder<'a> for ParserImpl<'a, C> {
|
||||
mod test {
|
||||
use std::path::Path;
|
||||
|
||||
use oxc_ast::ast::{CommentKind, Expression, Statement};
|
||||
use oxc_ast::ast::{
|
||||
CommentKind, Expression, Statement, TSNamespaceDeclarationBody, TSNamespaceDeclarationKind,
|
||||
};
|
||||
use oxc_span::GetSpan;
|
||||
|
||||
use super::*;
|
||||
@@ -987,9 +989,40 @@ mod test {
|
||||
fn ts_module_declaration() {
|
||||
let allocator = Allocator::default();
|
||||
let source_type = SourceType::from_path(Path::new("module.ts")).unwrap();
|
||||
let source = "declare module 'test'\n";
|
||||
let source =
|
||||
"declare module 'test'; namespace Foo.Bar {} module Baz {} declare module 'raw' {}";
|
||||
let ret = Parser::new(&allocator, source, source_type).parse();
|
||||
assert_eq!(ret.diagnostics.len(), 0);
|
||||
assert!(ret.diagnostics.is_empty());
|
||||
|
||||
let Statement::TSExternalModuleDeclaration(external) = &ret.program.body[0] else {
|
||||
panic!("expected external module declaration");
|
||||
};
|
||||
assert_eq!(external.id.value, "test");
|
||||
assert!(external.body.is_none());
|
||||
assert!(external.declare);
|
||||
|
||||
let Statement::TSNamespaceDeclaration(namespace) = &ret.program.body[1] else {
|
||||
panic!("expected namespace declaration");
|
||||
};
|
||||
assert_eq!(namespace.id.name, "Foo");
|
||||
assert_eq!(namespace.kind, TSNamespaceDeclarationKind::Namespace);
|
||||
let TSNamespaceDeclarationBody::TSNamespaceDeclaration(inner) = &namespace.body else {
|
||||
panic!("expected dotted namespace declaration");
|
||||
};
|
||||
assert_eq!(inner.id.name, "Bar");
|
||||
|
||||
let Statement::TSNamespaceDeclaration(module) = &ret.program.body[2] else {
|
||||
panic!("expected identifier module declaration");
|
||||
};
|
||||
assert_eq!(module.id.name, "Baz");
|
||||
assert_eq!(module.kind, TSNamespaceDeclarationKind::Module);
|
||||
|
||||
let Statement::TSExternalModuleDeclaration(external) = &ret.program.body[3] else {
|
||||
panic!("expected external module declaration");
|
||||
};
|
||||
assert_eq!(external.id.value, "raw");
|
||||
assert!(external.body.is_some());
|
||||
assert!(external.declare);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -390,32 +390,35 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
&mut self,
|
||||
start: u32,
|
||||
modifiers: &Modifiers,
|
||||
) -> ArenaBox<'a, TSModuleDeclaration<'a>> {
|
||||
) -> Declaration<'a> {
|
||||
let kind = if self.eat(Kind::Namespace) {
|
||||
TSModuleDeclarationKind::Namespace
|
||||
TSNamespaceDeclarationKind::Namespace
|
||||
} else {
|
||||
self.expect(Kind::Module);
|
||||
if self.at(Kind::Str) {
|
||||
return self.parse_ambient_external_module_declaration(start, modifiers);
|
||||
return Declaration::TSExternalModuleDeclaration(
|
||||
self.parse_ambient_external_module_declaration(start, modifiers),
|
||||
);
|
||||
}
|
||||
TSModuleDeclarationKind::Module
|
||||
TSNamespaceDeclarationKind::Module
|
||||
};
|
||||
self.parse_module_or_namespace_declaration(start, kind, modifiers)
|
||||
Declaration::TSNamespaceDeclaration(
|
||||
self.parse_module_or_namespace_declaration(start, kind, modifiers),
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_ambient_external_module_declaration(
|
||||
&mut self,
|
||||
start: u32,
|
||||
modifiers: &Modifiers,
|
||||
) -> ArenaBox<'a, TSModuleDeclaration<'a>> {
|
||||
let id = TSModuleDeclarationName::StringLiteral(self.parse_literal_string());
|
||||
) -> ArenaBox<'a, TSExternalModuleDeclaration<'a>> {
|
||||
let id = self.parse_literal_string();
|
||||
if !self.ctx.has_ambient() {
|
||||
self.error(diagnostics::quoted_module_name_only_allowed_in_ambient_module(id.span()));
|
||||
}
|
||||
let body = if self.at(Kind::LCurly) {
|
||||
// External module body (`declare module "x" {}`); `import`/`export` are allowed here.
|
||||
let block = self.parse_ts_module_block(/* in_ts_namespace_body */ false);
|
||||
Some(TSModuleDeclarationBody::TSModuleBlock(block))
|
||||
Some(self.parse_ts_module_block(/* in_ts_namespace_body */ false))
|
||||
} else {
|
||||
self.asi();
|
||||
None
|
||||
@@ -426,11 +429,10 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
true,
|
||||
diagnostics::modifier_cannot_be_used_here,
|
||||
);
|
||||
TSModuleDeclaration::boxed(
|
||||
TSExternalModuleDeclaration::boxed(
|
||||
self.end_span(start),
|
||||
id,
|
||||
body,
|
||||
TSModuleDeclarationKind::Module,
|
||||
modifiers.contains_declare(),
|
||||
self,
|
||||
)
|
||||
@@ -504,19 +506,19 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
fn parse_module_or_namespace_declaration(
|
||||
&mut self,
|
||||
start: u32,
|
||||
kind: TSModuleDeclarationKind,
|
||||
kind: TSNamespaceDeclarationKind,
|
||||
modifiers: &Modifiers,
|
||||
) -> ArenaBox<'a, TSModuleDeclaration<'a>> {
|
||||
let id = TSModuleDeclarationName::Identifier(self.parse_binding_identifier());
|
||||
) -> ArenaBox<'a, TSNamespaceDeclaration<'a>> {
|
||||
let id = self.parse_binding_identifier();
|
||||
let body = if self.eat(Kind::Dot) {
|
||||
let start = self.cur_start();
|
||||
let decl = self.parse_module_or_namespace_declaration(start, kind, &Modifiers::empty());
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(decl)
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(decl)
|
||||
} else {
|
||||
// Internal namespace body — validate each statement inline as it is parsed
|
||||
// (see `check_namespace_body_statement`), avoiding a second pass over the body.
|
||||
let block = self.parse_ts_module_block(/* in_ts_namespace_body */ true);
|
||||
TSModuleDeclarationBody::TSModuleBlock(block)
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block)
|
||||
};
|
||||
self.verify_modifiers(
|
||||
modifiers,
|
||||
@@ -524,10 +526,10 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
true,
|
||||
diagnostics::modifier_cannot_be_used_here,
|
||||
);
|
||||
TSModuleDeclaration::boxed(
|
||||
TSNamespaceDeclaration::boxed(
|
||||
self.end_span(start),
|
||||
id,
|
||||
Some(body),
|
||||
body,
|
||||
kind,
|
||||
modifiers.contains_declare(),
|
||||
self,
|
||||
@@ -658,8 +660,7 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
self.parse_ts_import_equals_declaration(import_kind, identifier, start)
|
||||
}
|
||||
Kind::Module | Kind::Namespace if self.is_ts => {
|
||||
let decl = self.parse_ts_module_declaration(start, modifiers);
|
||||
Declaration::TSModuleDeclaration(decl)
|
||||
self.parse_ts_module_declaration(start, modifiers)
|
||||
}
|
||||
Kind::Global if self.is_ts => {
|
||||
let decl = self.parse_ts_global_declaration(start, modifiers);
|
||||
|
||||
@@ -292,7 +292,9 @@ impl<'a> VisitJs<'a> for ContextIdentifierVisitor<'a> {
|
||||
|
||||
fn visit_ts_enum_declaration(&mut self, _it: &TSEnumDeclaration<'a>) {}
|
||||
|
||||
fn visit_ts_module_declaration(&mut self, _it: &TSModuleDeclaration<'a>) {}
|
||||
fn visit_ts_external_module_declaration(&mut self, _it: &TSExternalModuleDeclaration<'a>) {}
|
||||
|
||||
fn visit_ts_namespace_declaration(&mut self, _it: &TSNamespaceDeclaration<'a>) {}
|
||||
}
|
||||
|
||||
impl<'a> ContextIdentifierVisitor<'a> {
|
||||
|
||||
@@ -256,7 +256,9 @@ impl<'a> Visit<'a> for IdentifierLocVisitor {
|
||||
|
||||
fn visit_ts_enum_declaration(&mut self, _it: &TSEnumDeclaration<'a>) {}
|
||||
|
||||
fn visit_ts_module_declaration(&mut self, _it: &TSModuleDeclaration<'a>) {}
|
||||
fn visit_ts_external_module_declaration(&mut self, _it: &TSExternalModuleDeclaration<'a>) {}
|
||||
|
||||
fn visit_ts_namespace_declaration(&mut self, _it: &TSNamespaceDeclaration<'a>) {}
|
||||
}
|
||||
|
||||
/// Build an index of the resolved identifier references and binding
|
||||
|
||||
@@ -2,7 +2,7 @@ use oxc_allocator::Allocator;
|
||||
use oxc_ast::AstKind;
|
||||
use oxc_ast::ast::{
|
||||
BindingIdentifier, BindingPattern, IdentifierReference, ImportDeclaration, ModuleExportName,
|
||||
PropertyKind, TSModuleDeclarationName,
|
||||
PropertyKind,
|
||||
};
|
||||
use oxc_semantic::{AstNodes, NodeId, Scoping, Semantic};
|
||||
use oxc_span::GetSpan;
|
||||
@@ -236,7 +236,7 @@ impl<'s, 'a> ScopeResolver<'s, 'a> {
|
||||
AstKind::CatchParameter(_) => return BindingKind::Let,
|
||||
AstKind::TSTypeAliasDeclaration(_) => return BindingKind::Local,
|
||||
AstKind::TSEnumDeclaration(_) => return BindingKind::Local,
|
||||
AstKind::TSModuleDeclaration(_) => return BindingKind::Local,
|
||||
AstKind::TSNamespaceDeclaration(_) => return BindingKind::Local,
|
||||
AstKind::Function(_) => {
|
||||
if flags.contains(SymbolFlags::Function) {
|
||||
return BindingKind::Hoisted;
|
||||
@@ -317,7 +317,7 @@ impl<'s, 'a> ScopeResolver<'s, 'a> {
|
||||
AstKind::CatchClause(_) | AstKind::CatchParameter(_) => DeclKind::CatchClause,
|
||||
AstKind::TSTypeAliasDeclaration(_) => DeclKind::TSTypeAliasDeclaration,
|
||||
AstKind::TSEnumDeclaration(_) => DeclKind::TSEnumDeclaration,
|
||||
AstKind::TSModuleDeclaration(_) => DeclKind::TSModuleDeclaration,
|
||||
AstKind::TSNamespaceDeclaration(_) => DeclKind::TSModuleDeclaration,
|
||||
_ => DeclKind::Unknown,
|
||||
}
|
||||
}
|
||||
@@ -593,10 +593,9 @@ fn find_binding_identifier<'a>(kind: AstKind<'a>, name: &str) -> Option<&'a Bind
|
||||
(decl.id.name.as_str() == name).then_some(&decl.id)
|
||||
}
|
||||
AstKind::TSEnumDeclaration(decl) => (decl.id.name.as_str() == name).then_some(&decl.id),
|
||||
AstKind::TSModuleDeclaration(decl) => match &decl.id {
|
||||
TSModuleDeclarationName::Identifier(id) => (id.name.as_str() == name).then_some(id),
|
||||
_ => None,
|
||||
},
|
||||
AstKind::TSNamespaceDeclaration(decl) => {
|
||||
(decl.id.name.as_str() == name).then_some(&decl.id)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,9 +447,9 @@ impl<'a> Binder<'a> for TSEnumMember<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Binder<'a> for TSModuleDeclaration<'a> {
|
||||
impl<'a> Binder<'a> for TSNamespaceDeclaration<'a> {
|
||||
fn bind(&self, builder: &mut SemanticBuilder<'a>) {
|
||||
let TSModuleDeclarationName::Identifier(id) = &self.id else { return };
|
||||
let id = &self.id;
|
||||
let instantiated =
|
||||
get_module_instance_state(builder, self, builder.node_store.current_node_id)
|
||||
.is_instantiated();
|
||||
@@ -486,7 +486,7 @@ impl ModuleInstanceState {
|
||||
/// Based on `https://github.com/microsoft/TypeScript/blob/15392346d05045742e653eab5c87538ff2a3c863/src/compiler/binder.ts#L342-L474`
|
||||
fn get_module_instance_state<'a>(
|
||||
builder: &mut SemanticBuilder<'a>,
|
||||
decl: &TSModuleDeclaration<'a>,
|
||||
decl: &TSNamespaceDeclaration<'a>,
|
||||
current_node_id: NodeId,
|
||||
) -> ModuleInstanceState {
|
||||
get_module_instance_state_impl(builder, decl, current_node_id, &mut Vec::new())
|
||||
@@ -494,7 +494,7 @@ fn get_module_instance_state<'a>(
|
||||
|
||||
fn get_module_instance_state_impl<'a, 'b>(
|
||||
builder: &mut SemanticBuilder<'a>,
|
||||
decl: &'b TSModuleDeclaration<'a>,
|
||||
decl: &'b TSNamespaceDeclaration<'a>,
|
||||
current_node_id: NodeId,
|
||||
module_declaration_stmts: &mut Vec<&'b Statement<'a>>,
|
||||
) -> ModuleInstanceState {
|
||||
@@ -505,14 +505,9 @@ fn get_module_instance_state_impl<'a, 'b>(
|
||||
return *state;
|
||||
}
|
||||
|
||||
let Some(body) = &decl.body else {
|
||||
// For modules without a block, we consider them instantiated
|
||||
return ModuleInstanceState::Instantiated;
|
||||
};
|
||||
|
||||
// A module is uninstantiated if it contains only specific declarations
|
||||
let state = match body {
|
||||
TSModuleDeclarationBody::TSModuleBlock(block) => {
|
||||
let state = match &decl.body {
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => {
|
||||
module_declaration_stmts.extend(block.body.iter());
|
||||
|
||||
let mut child_state = ModuleInstanceState::NonInstantiated;
|
||||
@@ -529,8 +524,8 @@ fn get_module_instance_state_impl<'a, 'b>(
|
||||
}
|
||||
child_state
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(module) => {
|
||||
get_module_instance_state(builder, module, current_node_id)
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(namespace) => {
|
||||
get_module_instance_state(builder, namespace, current_node_id)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -538,6 +533,40 @@ fn get_module_instance_state_impl<'a, 'b>(
|
||||
state
|
||||
}
|
||||
|
||||
fn get_external_module_instance_state_impl<'a, 'b>(
|
||||
builder: &mut SemanticBuilder<'a>,
|
||||
decl: &'b TSExternalModuleDeclaration<'a>,
|
||||
current_node_id: NodeId,
|
||||
module_declaration_stmts: &mut Vec<&'b Statement<'a>>,
|
||||
) -> ModuleInstanceState {
|
||||
let address = decl.unstable_address();
|
||||
|
||||
if let Some(state) = builder.module_instance_state_cache.get(&address) {
|
||||
return *state;
|
||||
}
|
||||
|
||||
let Some(block) = &decl.body else {
|
||||
return ModuleInstanceState::Instantiated;
|
||||
};
|
||||
|
||||
module_declaration_stmts.extend(block.body.iter());
|
||||
let mut state = ModuleInstanceState::NonInstantiated;
|
||||
for stmt in &block.body {
|
||||
state = get_module_instance_state_for_statement(
|
||||
builder,
|
||||
stmt,
|
||||
current_node_id,
|
||||
module_declaration_stmts,
|
||||
);
|
||||
if state.is_instantiated() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
builder.module_instance_state_cache.insert(address, state);
|
||||
state
|
||||
}
|
||||
|
||||
fn get_module_instance_state_for_statement<'a, 'b>(
|
||||
builder: &mut SemanticBuilder<'a>,
|
||||
stmt: &'b Statement<'a>,
|
||||
@@ -574,8 +603,11 @@ fn get_module_instance_state_for_statement<'a, 'b>(
|
||||
}
|
||||
Statement::ExportDeclaration(export_decl) => {
|
||||
match &export_decl.declaration {
|
||||
Declaration::TSModuleDeclaration(module_decl) => {
|
||||
get_module_instance_state_impl(builder, module_decl, current_node_id, module_declaration_stmts)
|
||||
Declaration::TSExternalModuleDeclaration(module_decl) => {
|
||||
get_external_module_instance_state_impl(builder, module_decl, current_node_id, module_declaration_stmts)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(namespace_decl) => {
|
||||
get_module_instance_state_impl(builder, namespace_decl, current_node_id, module_declaration_stmts)
|
||||
}
|
||||
decl => if decl.is_type() {
|
||||
ModuleInstanceState::NonInstantiated
|
||||
@@ -596,8 +628,11 @@ fn get_module_instance_state_for_statement<'a, 'b>(
|
||||
export_state
|
||||
}
|
||||
// 5. other module declarations
|
||||
Statement::TSModuleDeclaration(module_decl) => {
|
||||
get_module_instance_state_impl(builder, module_decl, current_node_id, module_declaration_stmts)
|
||||
Statement::TSNamespaceDeclaration(namespace_decl) => {
|
||||
get_module_instance_state_impl(builder, namespace_decl, current_node_id, module_declaration_stmts)
|
||||
}
|
||||
Statement::TSExternalModuleDeclaration(module_decl) => {
|
||||
get_external_module_instance_state_impl(builder, module_decl, current_node_id, module_declaration_stmts)
|
||||
}
|
||||
// Any other type of statement means the module is instantiated
|
||||
_ => ModuleInstanceState::Instantiated,
|
||||
|
||||
@@ -2639,18 +2639,16 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
|
||||
self.leave_node(kind);
|
||||
}
|
||||
|
||||
fn visit_ts_module_declaration(&mut self, decl: &TSModuleDeclaration<'a>) {
|
||||
let kind = AstKind::TSModuleDeclaration(self.alloc(decl));
|
||||
fn visit_ts_external_module_declaration(&mut self, decl: &TSExternalModuleDeclaration<'a>) {
|
||||
let kind = AstKind::TSExternalModuleDeclaration(self.alloc(decl));
|
||||
self.enter_node(kind);
|
||||
self.enter_ambient_context(decl.declare);
|
||||
decl.bind(self);
|
||||
self.visit_span(&decl.span);
|
||||
self.visit_ts_module_declaration_name(&decl.id);
|
||||
self.visit_string_literal(&decl.id);
|
||||
self.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if decl.body.as_ref().is_some_and(TSModuleDeclarationBody::has_use_strict_directive)
|
||||
{
|
||||
if decl.has_use_strict_directive() {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
@@ -2658,13 +2656,36 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
|
||||
&decl.scope_id,
|
||||
);
|
||||
if let Some(body) = &decl.body {
|
||||
self.visit_ts_module_declaration_body(body);
|
||||
self.visit_ts_module_block(body);
|
||||
}
|
||||
self.leave_scope();
|
||||
self.leave_node(kind);
|
||||
self.leave_ambient_context(decl.declare);
|
||||
}
|
||||
|
||||
fn visit_ts_namespace_declaration(&mut self, decl: &TSNamespaceDeclaration<'a>) {
|
||||
let kind = AstKind::TSNamespaceDeclaration(self.alloc(decl));
|
||||
self.enter_node(kind);
|
||||
self.enter_ambient_context(decl.declare);
|
||||
decl.bind(self);
|
||||
self.visit_span(&decl.span);
|
||||
self.visit_binding_identifier(&decl.id);
|
||||
self.enter_scope(
|
||||
{
|
||||
let mut flags = ScopeFlags::TsModuleBlock;
|
||||
if decl.has_use_strict_directive() {
|
||||
flags |= ScopeFlags::StrictMode;
|
||||
}
|
||||
flags
|
||||
},
|
||||
&decl.scope_id,
|
||||
);
|
||||
self.visit_ts_namespace_declaration_body(&decl.body);
|
||||
self.leave_scope();
|
||||
self.leave_node(kind);
|
||||
self.leave_ambient_context(decl.declare);
|
||||
}
|
||||
|
||||
fn visit_ts_global_declaration(&mut self, decl: &TSGlobalDeclaration<'a>) {
|
||||
let kind = AstKind::TSGlobalDeclaration(self.alloc(decl));
|
||||
self.enter_node(kind);
|
||||
|
||||
@@ -105,7 +105,12 @@ pub fn check<'a>(kind: AstKind<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
}
|
||||
AstKind::TSTypeAnnotation(annot) => ts::check_ts_type_annotation(annot, ctx),
|
||||
AstKind::TSTypePredicate(predicate) => ts::check_ts_type_predicate(predicate, ctx),
|
||||
AstKind::TSModuleDeclaration(decl) => ts::check_ts_module_declaration(decl, ctx),
|
||||
AstKind::TSExternalModuleDeclaration(decl) => {
|
||||
ts::check_ts_external_module_declaration(decl, ctx);
|
||||
}
|
||||
AstKind::TSNamespaceDeclaration(decl) => {
|
||||
ts::check_ts_namespace_declaration(decl, ctx);
|
||||
}
|
||||
AstKind::TSGlobalDeclaration(decl) => ts::check_ts_global_declaration(decl, ctx),
|
||||
AstKind::TSEnumDeclaration(decl) => ts::check_ts_enum_declaration(decl, ctx),
|
||||
AstKind::TSInferType(infer_type) => ts::check_ts_infer_type(infer_type, ctx),
|
||||
|
||||
@@ -98,13 +98,22 @@ fn check_duplicate_bound_names<'a, T: BoundNames<'a>>(bound_names: &T, ctx: &Sem
|
||||
});
|
||||
}
|
||||
|
||||
pub fn check_ts_module_declaration<'a>(decl: &TSModuleDeclaration<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
if matches!(&decl.id, TSModuleDeclarationName::StringLiteral(_)) {
|
||||
check_ambient_module_declaration(decl.span, ctx);
|
||||
} else {
|
||||
check_ts_module_or_global_declaration(decl.span, ctx);
|
||||
pub fn check_ts_external_module_declaration<'a>(
|
||||
decl: &TSExternalModuleDeclaration<'a>,
|
||||
ctx: &SemanticBuilder<'a>,
|
||||
) {
|
||||
check_ambient_module_declaration(decl.span, ctx);
|
||||
if let Some(body) = &decl.body {
|
||||
check_ts_export_assignment_in_statements(&body.body, ctx);
|
||||
}
|
||||
check_ts_export_assignment_in_module_decl(decl, ctx);
|
||||
}
|
||||
|
||||
pub fn check_ts_namespace_declaration<'a>(
|
||||
decl: &TSNamespaceDeclaration<'a>,
|
||||
ctx: &SemanticBuilder<'a>,
|
||||
) {
|
||||
check_ts_module_or_global_declaration(decl.span, ctx);
|
||||
check_ts_export_assignment_in_namespace_decl(decl, ctx);
|
||||
}
|
||||
|
||||
pub fn check_ts_global_declaration<'a>(decl: &TSGlobalDeclaration<'a>, ctx: &SemanticBuilder<'a>) {
|
||||
@@ -123,7 +132,8 @@ fn check_ts_module_or_global_declaration(span: Span, ctx: &SemanticBuilder<'_>)
|
||||
match kind {
|
||||
AstKind::Program(_)
|
||||
| AstKind::TSModuleBlock(_)
|
||||
| AstKind::TSModuleDeclaration(_)
|
||||
| AstKind::TSExternalModuleDeclaration(_)
|
||||
| AstKind::TSNamespaceDeclaration(_)
|
||||
| AstKind::TSGlobalDeclaration(_) => {
|
||||
break;
|
||||
}
|
||||
@@ -145,19 +155,26 @@ fn check_ambient_module_declaration(span: Span, ctx: &SemanticBuilder<'_>) {
|
||||
match ancestors.next() {
|
||||
Some(AstKind::Program(_)) => {}
|
||||
Some(AstKind::TSModuleBlock(_)) => match ancestors.next() {
|
||||
Some(AstKind::TSModuleDeclaration(decl))
|
||||
if matches!(&decl.id, TSModuleDeclarationName::StringLiteral(_))
|
||||
&& ctx.source_type.is_script()
|
||||
Some(AstKind::TSExternalModuleDeclaration(_))
|
||||
if ctx.source_type.is_script()
|
||||
&& matches!(ancestors.next(), Some(AstKind::Program(_))) =>
|
||||
{
|
||||
// Module augmentations may be nested directly in a top-level ambient module.
|
||||
}
|
||||
Some(AstKind::TSModuleDeclaration(_) | AstKind::TSGlobalDeclaration(_)) => {
|
||||
Some(
|
||||
AstKind::TSExternalModuleDeclaration(_)
|
||||
| AstKind::TSNamespaceDeclaration(_)
|
||||
| AstKind::TSGlobalDeclaration(_),
|
||||
) => {
|
||||
ctx.error(diagnostics::nested_ambient_module_declaration(span));
|
||||
}
|
||||
_ => ctx.error(diagnostics::not_allowed_ambient_module_declaration(span)),
|
||||
},
|
||||
Some(AstKind::TSModuleDeclaration(_) | AstKind::TSGlobalDeclaration(_)) => {
|
||||
Some(
|
||||
AstKind::TSExternalModuleDeclaration(_)
|
||||
| AstKind::TSNamespaceDeclaration(_)
|
||||
| AstKind::TSGlobalDeclaration(_),
|
||||
) => {
|
||||
ctx.error(diagnostics::nested_ambient_module_declaration(span));
|
||||
}
|
||||
_ => ctx.error(diagnostics::not_allowed_ambient_module_declaration(span)),
|
||||
@@ -274,18 +291,15 @@ pub fn check_ts_export_assignment_in_program<'a>(program: &Program<'a>, ctx: &Se
|
||||
check_ts_export_assignment_in_statements(&program.body, ctx);
|
||||
}
|
||||
|
||||
fn check_ts_export_assignment_in_module_decl<'a>(
|
||||
module_decl: &TSModuleDeclaration<'a>,
|
||||
fn check_ts_export_assignment_in_namespace_decl<'a>(
|
||||
namespace_decl: &TSNamespaceDeclaration<'a>,
|
||||
ctx: &SemanticBuilder<'a>,
|
||||
) {
|
||||
let Some(body) = &module_decl.body else {
|
||||
return;
|
||||
};
|
||||
match body {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(nested) => {
|
||||
check_ts_export_assignment_in_module_decl(nested, ctx);
|
||||
match &namespace_decl.body {
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(nested) => {
|
||||
check_ts_export_assignment_in_namespace_decl(nested, ctx);
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(block) => {
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => {
|
||||
check_ts_export_assignment_in_statements(&block.body, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use oxc_ast::{
|
||||
AstKind,
|
||||
ast::{BindingIdentifier, BindingPattern, TSModuleDeclarationName},
|
||||
ast::{BindingIdentifier, BindingPattern},
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_span::{GetSpan, Span};
|
||||
@@ -102,16 +102,7 @@ impl ConformanceTest for SymbolDeclarationTest {
|
||||
AstKind::TSImportEqualsDeclaration(import) => check_binding(symbol_id, &import.id),
|
||||
AstKind::TSTypeParameter(decl) => check_binding(symbol_id, &decl.name),
|
||||
AstKind::TSMappedType(decl) => check_binding(symbol_id, &decl.key),
|
||||
AstKind::TSModuleDeclaration(decl) => match &decl.id {
|
||||
TSModuleDeclarationName::Identifier(id) => check_binding(symbol_id, id),
|
||||
TSModuleDeclarationName::StringLiteral(_) => {
|
||||
bound_to_statement_with_no_binding_identifier(
|
||||
symbol_id,
|
||||
span,
|
||||
"TSModuleDeclaration",
|
||||
)
|
||||
}
|
||||
},
|
||||
AstKind::TSNamespaceDeclaration(decl) => check_binding(symbol_id, &decl.id),
|
||||
AstKind::TSTypeAliasDeclaration(decl) => check_binding(symbol_id, &decl.id),
|
||||
AstKind::TSInterfaceDeclaration(decl) => check_binding(symbol_id, &decl.id),
|
||||
AstKind::TSEnumDeclaration(decl) => check_binding(symbol_id, &decl.id),
|
||||
|
||||
@@ -17,7 +17,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/namespaces/value-module.ts
|
||||
],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(N1)",
|
||||
"node": "TSNamespaceDeclaration(N1)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
@@ -51,7 +51,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/namespaces/value-module.ts
|
||||
"flags": "SymbolFlags(ValueModule)",
|
||||
"id": 0,
|
||||
"name": "N1",
|
||||
"node": "TSModuleDeclaration(N1)",
|
||||
"node": "TSNamespaceDeclaration(N1)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Type)",
|
||||
|
||||
+6
-6
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/equals-t
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(Bar)",
|
||||
"node": "TSNamespaceDeclaration(Bar)",
|
||||
"symbols": []
|
||||
},
|
||||
{
|
||||
@@ -18,19 +18,19 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/equals-t
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 3,
|
||||
"node": "TSModuleDeclaration(Baz)",
|
||||
"node": "TSNamespaceDeclaration(Baz)",
|
||||
"symbols": []
|
||||
}
|
||||
],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 2,
|
||||
"node": "TSModuleDeclaration(Qux)",
|
||||
"node": "TSNamespaceDeclaration(Qux)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(NamespaceModule)",
|
||||
"id": 2,
|
||||
"name": "Baz",
|
||||
"node": "TSModuleDeclaration(Baz)",
|
||||
"node": "TSNamespaceDeclaration(Baz)",
|
||||
"references": []
|
||||
}
|
||||
]
|
||||
@@ -44,7 +44,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/equals-t
|
||||
"flags": "SymbolFlags(NamespaceModule)",
|
||||
"id": 0,
|
||||
"name": "Bar",
|
||||
"node": "TSModuleDeclaration(Bar)",
|
||||
"node": "TSNamespaceDeclaration(Bar)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Type)",
|
||||
@@ -59,7 +59,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/equals-t
|
||||
"flags": "SymbolFlags(NamespaceModule)",
|
||||
"id": 1,
|
||||
"name": "Qux",
|
||||
"node": "TSModuleDeclaration(Qux)",
|
||||
"node": "TSNamespaceDeclaration(Qux)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Type)",
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/decla
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 2,
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/decla
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 2,
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/decla
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"symbols": []
|
||||
}
|
||||
],
|
||||
@@ -21,7 +21,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/decla
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable | NamespaceModule)",
|
||||
"id": 0,
|
||||
"name": "Foo",
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Read)",
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/exter
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
@@ -29,7 +29,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/exter
|
||||
"flags": "SymbolFlags(ValueModule)",
|
||||
"id": 0,
|
||||
"name": "Foo",
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Read)",
|
||||
|
||||
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/impor
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(foo)",
|
||||
"node": "TSExternalModuleDeclaration(foo)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(Import)",
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/name-
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
@@ -29,7 +29,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/name-
|
||||
"flags": "SymbolFlags(ValueModule)",
|
||||
"id": 0,
|
||||
"name": "Foo",
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Read)",
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/names
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
@@ -29,7 +29,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/names
|
||||
"flags": "SymbolFlags(ValueModule)",
|
||||
"id": 0,
|
||||
"name": "Foo",
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Read)",
|
||||
|
||||
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/scope
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
@@ -29,7 +29,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/scope
|
||||
"flags": "SymbolFlags(ValueModule)",
|
||||
"id": 0,
|
||||
"name": "Foo",
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"references": []
|
||||
},
|
||||
{
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/self-
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
@@ -29,7 +29,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/self-
|
||||
"flags": "SymbolFlags(ValueModule)",
|
||||
"id": 0,
|
||||
"name": "Foo",
|
||||
"node": "TSModuleDeclaration(Foo)",
|
||||
"node": "TSNamespaceDeclaration(Foo)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Read)",
|
||||
|
||||
Vendored
+2
-2
@@ -24,7 +24,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 2,
|
||||
"node": "TSModuleDeclaration(Member)",
|
||||
"node": "TSNamespaceDeclaration(Member)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(TypeAlias)",
|
||||
@@ -58,7 +58,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"flags": "SymbolFlags(NamespaceModule)",
|
||||
"id": 1,
|
||||
"name": "Member",
|
||||
"node": "TSModuleDeclaration(Member)",
|
||||
"node": "TSNamespaceDeclaration(Member)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Type)",
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(T)",
|
||||
"node": "TSNamespaceDeclaration(T)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(Class)",
|
||||
@@ -76,7 +76,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"flags": "SymbolFlags(ValueModule)",
|
||||
"id": 0,
|
||||
"name": "T",
|
||||
"node": "TSModuleDeclaration(T)",
|
||||
"node": "TSNamespaceDeclaration(T)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Read)",
|
||||
|
||||
+4
-4
@@ -35,7 +35,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 2,
|
||||
"node": "TSModuleDeclaration(B)",
|
||||
"node": "TSNamespaceDeclaration(B)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(TypeAlias)",
|
||||
@@ -49,13 +49,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(A)",
|
||||
"node": "TSNamespaceDeclaration(A)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(NamespaceModule)",
|
||||
"id": 1,
|
||||
"name": "B",
|
||||
"node": "TSModuleDeclaration(B)",
|
||||
"node": "TSNamespaceDeclaration(B)",
|
||||
"references": []
|
||||
}
|
||||
]
|
||||
@@ -92,7 +92,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"flags": "SymbolFlags(NamespaceModule)",
|
||||
"id": 0,
|
||||
"name": "A",
|
||||
"node": "TSModuleDeclaration(A)",
|
||||
"node": "TSNamespaceDeclaration(A)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Type)",
|
||||
|
||||
Vendored
+2
-2
@@ -33,7 +33,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
],
|
||||
"flags": "ScopeFlags(TsModuleBlock)",
|
||||
"id": 1,
|
||||
"node": "TSModuleDeclaration(Database)",
|
||||
"node": "TSNamespaceDeclaration(Database)",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(TypeAlias)",
|
||||
@@ -76,7 +76,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
|
||||
"flags": "SymbolFlags(NamespaceModule)",
|
||||
"id": 0,
|
||||
"name": "Database",
|
||||
"node": "TSModuleDeclaration(Database)",
|
||||
"node": "TSNamespaceDeclaration(Database)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Type)",
|
||||
|
||||
@@ -477,7 +477,8 @@ impl<'a> Traverse<'a, TransformState<'a>> for ExplicitResourceManagement<'a> {
|
||||
| Declaration::TSTypeAliasDeclaration(_)
|
||||
| Declaration::TSInterfaceDeclaration(_)
|
||||
| Declaration::TSEnumDeclaration(_)
|
||||
| Declaration::TSModuleDeclaration(_)
|
||||
| Declaration::TSExternalModuleDeclaration(_)
|
||||
| Declaration::TSNamespaceDeclaration(_)
|
||||
// Note: `TSGlobalDeclaration` cannot be exported
|
||||
| Declaration::TSImportEqualsDeclaration(_)
|
||||
) {
|
||||
|
||||
@@ -518,10 +518,11 @@ impl<'a> TypeScriptAnnotations<'a> {
|
||||
#[inline]
|
||||
fn should_keep_declaration(&self, decl: &Declaration<'a>, ctx: &mut TraverseCtx<'a>) -> bool {
|
||||
match decl {
|
||||
// Remove type aliases, interfaces, and `declare global {}`
|
||||
// Remove type aliases, interfaces, global declarations, and external modules.
|
||||
Declaration::TSTypeAliasDeclaration(_)
|
||||
| Declaration::TSInterfaceDeclaration(_)
|
||||
| Declaration::TSGlobalDeclaration(_) => false,
|
||||
| Declaration::TSGlobalDeclaration(_)
|
||||
| Declaration::TSExternalModuleDeclaration(_) => false,
|
||||
// Remove `declare var/let/const`
|
||||
Declaration::VariableDeclaration(var_decl) => !var_decl.declare,
|
||||
// Remove `declare function` and function overload signatures (no body)
|
||||
@@ -530,16 +531,15 @@ impl<'a> TypeScriptAnnotations<'a> {
|
||||
}
|
||||
// Remove `declare class`
|
||||
Declaration::ClassDeclaration(class_decl) => !class_decl.declare,
|
||||
// Remove `declare module` or uninstantiated namespace declarations.
|
||||
// Remove declared or uninstantiated namespace declarations.
|
||||
// Keep instantiated `module` declarations — they have runtime
|
||||
// representation and need to be transformed.
|
||||
Declaration::TSModuleDeclaration(module_decl) => {
|
||||
!module_decl.declare
|
||||
&& !matches!(
|
||||
&module_decl.id,
|
||||
TSModuleDeclarationName::Identifier(ident)
|
||||
if ctx.scoping().symbol_flags(ident.symbol_id()).is_namespace_module()
|
||||
)
|
||||
Declaration::TSNamespaceDeclaration(namespace_decl) => {
|
||||
!namespace_decl.declare
|
||||
&& !ctx
|
||||
.scoping()
|
||||
.symbol_flags(namespace_decl.id.symbol_id())
|
||||
.is_namespace_module()
|
||||
}
|
||||
// Remove `declare enum`
|
||||
Declaration::TSEnumDeclaration(enum_decl) => !enum_decl.declare,
|
||||
|
||||
@@ -44,7 +44,15 @@ impl<'a> Traverse<'a, TransformState<'a>> for TypeScriptNamespace {
|
||||
|
||||
for stmt in program.body.take_in(ctx) {
|
||||
match stmt {
|
||||
Statement::TSModuleDeclaration(decl) => {
|
||||
Statement::TSExternalModuleDeclaration(decl) => {
|
||||
if !self.allow_namespaces {
|
||||
ctx.state.error(namespace_not_supported(decl.span));
|
||||
}
|
||||
|
||||
Self::handle_external(&decl, ctx);
|
||||
continue;
|
||||
}
|
||||
Statement::TSNamespaceDeclaration(decl) => {
|
||||
if !self.allow_namespaces {
|
||||
ctx.state.error(namespace_not_supported(decl.span));
|
||||
}
|
||||
@@ -63,19 +71,31 @@ impl<'a> Traverse<'a, TransformState<'a>> for TypeScriptNamespace {
|
||||
let declaration = &export_decl.declaration;
|
||||
// Note: No need to check for `TSGlobalDeclaration` here, as it can't be exported
|
||||
debug_assert!(!matches!(declaration, Declaration::TSGlobalDeclaration(_)));
|
||||
matches!(declaration, Declaration::TSModuleDeclaration(module_decl) if !module_decl.declare)
|
||||
matches!(declaration, Declaration::TSExternalModuleDeclaration(module_decl) if !module_decl.declare)
|
||||
|| matches!(declaration, Declaration::TSNamespaceDeclaration(namespace_decl) if !namespace_decl.declare)
|
||||
} =>
|
||||
{
|
||||
let Declaration::TSModuleDeclaration(decl) = export_decl.unbox().declaration
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
if !self.allow_namespaces {
|
||||
ctx.state.error(namespace_not_supported(decl.span));
|
||||
match export_decl.unbox().declaration {
|
||||
Declaration::TSExternalModuleDeclaration(decl) => {
|
||||
if !self.allow_namespaces {
|
||||
ctx.state.error(namespace_not_supported(decl.span));
|
||||
}
|
||||
Self::handle_external(&decl, ctx);
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(decl) => {
|
||||
if !self.allow_namespaces {
|
||||
ctx.state.error(namespace_not_supported(decl.span));
|
||||
}
|
||||
self.handle_nested(
|
||||
decl,
|
||||
/* is_export */ true,
|
||||
&mut new_stmts,
|
||||
None,
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
self.handle_nested(decl, /* is_export */ true, &mut new_stmts, None, ctx);
|
||||
continue;
|
||||
}
|
||||
_ => {}
|
||||
@@ -89,10 +109,16 @@ impl<'a> Traverse<'a, TransformState<'a>> for TypeScriptNamespace {
|
||||
}
|
||||
|
||||
impl<'a> TypeScriptNamespace {
|
||||
fn handle_external(decl: &TSExternalModuleDeclaration<'a>, ctx: &mut TraverseCtx<'a>) {
|
||||
if !decl.declare {
|
||||
ctx.state.error(ambient_module_nested(decl.span));
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(clippy::self_only_used_in_recursion)]
|
||||
fn handle_nested(
|
||||
&self,
|
||||
decl: ArenaBox<'a, TSModuleDeclaration<'a>>,
|
||||
decl: ArenaBox<'a, TSNamespaceDeclaration<'a>>,
|
||||
is_export: bool,
|
||||
parent_stmts: &mut ArenaVec<'a, Statement<'a>>,
|
||||
parent_binding: Option<&BoundIdentifier<'a>>,
|
||||
@@ -102,13 +128,7 @@ impl<'a> TypeScriptNamespace {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip empty declaration e.g. `namespace x;`
|
||||
let TSModuleDeclaration { span, id, body, scope_id, .. } = decl.unbox();
|
||||
|
||||
let TSModuleDeclarationName::Identifier(ident) = id else {
|
||||
ctx.state.error(ambient_module_nested(span));
|
||||
return;
|
||||
};
|
||||
let TSNamespaceDeclaration { span, id: ident, body, scope_id, .. } = decl.unbox();
|
||||
|
||||
// Return early if this declaration is empty or only contains type declarations —
|
||||
// it emits no JS.
|
||||
@@ -155,13 +175,9 @@ impl<'a> TypeScriptNamespace {
|
||||
}
|
||||
}
|
||||
|
||||
let Some(body) = body else {
|
||||
return;
|
||||
};
|
||||
|
||||
let binding = BoundIdentifier::from_binding_ident(&ident);
|
||||
|
||||
// Reuse `TSModuleDeclaration`'s scope in transformed function
|
||||
// Reuse `TSNamespaceDeclaration`'s scope in transformed function
|
||||
let scope_id = scope_id.get().unwrap();
|
||||
let uid_binding =
|
||||
ctx.generate_uid(&binding.name, scope_id, SymbolFlags::FunctionScopedVariable);
|
||||
@@ -170,7 +186,7 @@ impl<'a> TypeScriptNamespace {
|
||||
let namespace_top_level;
|
||||
|
||||
match body {
|
||||
TSModuleDeclarationBody::TSModuleBlock(block) => {
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(block) => {
|
||||
let block = block.unbox();
|
||||
directives = block.directives;
|
||||
namespace_top_level = block.body;
|
||||
@@ -179,8 +195,8 @@ impl<'a> TypeScriptNamespace {
|
||||
// namespace X {
|
||||
// export namespace Y {}
|
||||
// }
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(declaration) => {
|
||||
let declaration = Declaration::TSModuleDeclaration(declaration);
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(declaration) => {
|
||||
let declaration = Declaration::TSNamespaceDeclaration(declaration);
|
||||
let export_decl = ExportDeclaration::boxed(SPAN, declaration, ctx);
|
||||
let stmt = Statement::ExportDeclaration(export_decl);
|
||||
directives = ArenaVec::new_in(ctx);
|
||||
@@ -192,13 +208,16 @@ impl<'a> TypeScriptNamespace {
|
||||
|
||||
for stmt in namespace_top_level {
|
||||
match stmt {
|
||||
Statement::TSModuleDeclaration(decl) => {
|
||||
Statement::TSExternalModuleDeclaration(decl) => {
|
||||
Self::handle_external(&decl, ctx);
|
||||
}
|
||||
Statement::TSNamespaceDeclaration(decl) => {
|
||||
self.handle_nested(decl, /* is_export */ false, &mut new_stmts, None, ctx);
|
||||
}
|
||||
Statement::TSGlobalDeclaration(_) => {
|
||||
// Remove it.
|
||||
// Note: It is legal to have a `TSGlobalDeclaration` nested within a `TSModuleDeclaration`,
|
||||
// where identifier is a string literal: `declare module 'foo' { global {} }`
|
||||
// Note: It is legal to have a `TSGlobalDeclaration` nested within an external
|
||||
// module: `declare module 'foo' { global {} }`.
|
||||
}
|
||||
Statement::ExportDeclaration(export_decl) => {
|
||||
let decl = export_decl.unbox().declaration;
|
||||
@@ -244,7 +263,10 @@ impl<'a> TypeScriptNamespace {
|
||||
Self::handle_variable_declaration(var_decl, &uid_binding, ctx);
|
||||
new_stmts.extend(stmts);
|
||||
}
|
||||
Declaration::TSModuleDeclaration(module_decl) => {
|
||||
Declaration::TSExternalModuleDeclaration(module_decl) => {
|
||||
Self::handle_external(&module_decl, ctx);
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(module_decl) => {
|
||||
self.handle_nested(
|
||||
module_decl,
|
||||
/* is_export */
|
||||
@@ -537,9 +559,15 @@ impl<'a> TypeScriptNamespace {
|
||||
/// Check if the statements contain a namespace declaration
|
||||
fn has_namespace(stmts: &[Statement]) -> bool {
|
||||
stmts.iter().any(|stmt| match stmt {
|
||||
Statement::TSModuleDeclaration(_) | Statement::TSGlobalDeclaration(_) => true,
|
||||
Statement::TSExternalModuleDeclaration(_)
|
||||
| Statement::TSNamespaceDeclaration(_)
|
||||
| Statement::TSGlobalDeclaration(_) => true,
|
||||
Statement::ExportDeclaration(decl) => {
|
||||
matches!(decl.declaration, Declaration::TSModuleDeclaration(_))
|
||||
matches!(
|
||||
decl.declaration,
|
||||
Declaration::TSExternalModuleDeclaration(_)
|
||||
| Declaration::TSNamespaceDeclaration(_)
|
||||
)
|
||||
}
|
||||
_ => false,
|
||||
})
|
||||
|
||||
@@ -277,51 +277,53 @@ pub(crate) enum AncestorType {
|
||||
TSInterfaceHeritageTypeArguments = 253,
|
||||
TSTypePredicateParameterName = 254,
|
||||
TSTypePredicateTypeAnnotation = 255,
|
||||
TSModuleDeclarationId = 256,
|
||||
TSModuleDeclarationBody = 257,
|
||||
TSGlobalDeclarationBody = 258,
|
||||
TSModuleBlockDirectives = 259,
|
||||
TSModuleBlockBody = 260,
|
||||
TSTypeLiteralMembers = 261,
|
||||
TSInferTypeTypeParameter = 262,
|
||||
TSTypeQueryExprName = 263,
|
||||
TSTypeQueryTypeArguments = 264,
|
||||
TSImportTypeSource = 265,
|
||||
TSImportTypeOptions = 266,
|
||||
TSImportTypeQualifier = 267,
|
||||
TSImportTypeTypeArguments = 268,
|
||||
TSImportTypeQualifiedNameLeft = 269,
|
||||
TSImportTypeQualifiedNameRight = 270,
|
||||
TSFunctionTypeTypeParameters = 271,
|
||||
TSFunctionTypeThisParam = 272,
|
||||
TSFunctionTypeParams = 273,
|
||||
TSFunctionTypeReturnType = 274,
|
||||
TSConstructorTypeTypeParameters = 275,
|
||||
TSConstructorTypeParams = 276,
|
||||
TSConstructorTypeReturnType = 277,
|
||||
TSMappedTypeKey = 278,
|
||||
TSMappedTypeConstraint = 279,
|
||||
TSMappedTypeNameType = 280,
|
||||
TSMappedTypeTypeAnnotation = 281,
|
||||
TSTemplateLiteralTypeQuasis = 282,
|
||||
TSTemplateLiteralTypeTypes = 283,
|
||||
TSAsExpressionExpression = 284,
|
||||
TSAsExpressionTypeAnnotation = 285,
|
||||
TSSatisfiesExpressionExpression = 286,
|
||||
TSSatisfiesExpressionTypeAnnotation = 287,
|
||||
TSTypeAssertionTypeAnnotation = 288,
|
||||
TSTypeAssertionExpression = 289,
|
||||
TSImportEqualsDeclarationId = 290,
|
||||
TSImportEqualsDeclarationModuleReference = 291,
|
||||
TSExternalModuleReferenceExpression = 292,
|
||||
TSNonNullExpressionExpression = 293,
|
||||
DecoratorExpression = 294,
|
||||
TSExportAssignmentExpression = 295,
|
||||
TSNamespaceExportDeclarationId = 296,
|
||||
TSInstantiationExpressionExpression = 297,
|
||||
TSInstantiationExpressionTypeArguments = 298,
|
||||
JSDocNullableTypeTypeAnnotation = 299,
|
||||
JSDocNonNullableTypeTypeAnnotation = 300,
|
||||
TSExternalModuleDeclarationId = 256,
|
||||
TSExternalModuleDeclarationBody = 257,
|
||||
TSNamespaceDeclarationId = 258,
|
||||
TSNamespaceDeclarationBody = 259,
|
||||
TSGlobalDeclarationBody = 260,
|
||||
TSModuleBlockDirectives = 261,
|
||||
TSModuleBlockBody = 262,
|
||||
TSTypeLiteralMembers = 263,
|
||||
TSInferTypeTypeParameter = 264,
|
||||
TSTypeQueryExprName = 265,
|
||||
TSTypeQueryTypeArguments = 266,
|
||||
TSImportTypeSource = 267,
|
||||
TSImportTypeOptions = 268,
|
||||
TSImportTypeQualifier = 269,
|
||||
TSImportTypeTypeArguments = 270,
|
||||
TSImportTypeQualifiedNameLeft = 271,
|
||||
TSImportTypeQualifiedNameRight = 272,
|
||||
TSFunctionTypeTypeParameters = 273,
|
||||
TSFunctionTypeThisParam = 274,
|
||||
TSFunctionTypeParams = 275,
|
||||
TSFunctionTypeReturnType = 276,
|
||||
TSConstructorTypeTypeParameters = 277,
|
||||
TSConstructorTypeParams = 278,
|
||||
TSConstructorTypeReturnType = 279,
|
||||
TSMappedTypeKey = 280,
|
||||
TSMappedTypeConstraint = 281,
|
||||
TSMappedTypeNameType = 282,
|
||||
TSMappedTypeTypeAnnotation = 283,
|
||||
TSTemplateLiteralTypeQuasis = 284,
|
||||
TSTemplateLiteralTypeTypes = 285,
|
||||
TSAsExpressionExpression = 286,
|
||||
TSAsExpressionTypeAnnotation = 287,
|
||||
TSSatisfiesExpressionExpression = 288,
|
||||
TSSatisfiesExpressionTypeAnnotation = 289,
|
||||
TSTypeAssertionTypeAnnotation = 290,
|
||||
TSTypeAssertionExpression = 291,
|
||||
TSImportEqualsDeclarationId = 292,
|
||||
TSImportEqualsDeclarationModuleReference = 293,
|
||||
TSExternalModuleReferenceExpression = 294,
|
||||
TSNonNullExpressionExpression = 295,
|
||||
DecoratorExpression = 296,
|
||||
TSExportAssignmentExpression = 297,
|
||||
TSNamespaceExportDeclarationId = 298,
|
||||
TSInstantiationExpressionExpression = 299,
|
||||
TSInstantiationExpressionTypeArguments = 300,
|
||||
JSDocNullableTypeTypeAnnotation = 301,
|
||||
JSDocNonNullableTypeTypeAnnotation = 302,
|
||||
}
|
||||
|
||||
/// Ancestor type used in AST traversal.
|
||||
@@ -817,10 +819,14 @@ pub enum Ancestor<'a, 't> {
|
||||
AncestorType::TSTypePredicateParameterName as u16,
|
||||
TSTypePredicateTypeAnnotation(TSTypePredicateWithoutTypeAnnotation<'a, 't>) =
|
||||
AncestorType::TSTypePredicateTypeAnnotation as u16,
|
||||
TSModuleDeclarationId(TSModuleDeclarationWithoutId<'a, 't>) =
|
||||
AncestorType::TSModuleDeclarationId as u16,
|
||||
TSModuleDeclarationBody(TSModuleDeclarationWithoutBody<'a, 't>) =
|
||||
AncestorType::TSModuleDeclarationBody as u16,
|
||||
TSExternalModuleDeclarationId(TSExternalModuleDeclarationWithoutId<'a, 't>) =
|
||||
AncestorType::TSExternalModuleDeclarationId as u16,
|
||||
TSExternalModuleDeclarationBody(TSExternalModuleDeclarationWithoutBody<'a, 't>) =
|
||||
AncestorType::TSExternalModuleDeclarationBody as u16,
|
||||
TSNamespaceDeclarationId(TSNamespaceDeclarationWithoutId<'a, 't>) =
|
||||
AncestorType::TSNamespaceDeclarationId as u16,
|
||||
TSNamespaceDeclarationBody(TSNamespaceDeclarationWithoutBody<'a, 't>) =
|
||||
AncestorType::TSNamespaceDeclarationBody as u16,
|
||||
TSGlobalDeclarationBody(TSGlobalDeclarationWithoutBody<'a, 't>) =
|
||||
AncestorType::TSGlobalDeclarationBody as u16,
|
||||
TSModuleBlockDirectives(TSModuleBlockWithoutDirectives<'a, 't>) =
|
||||
@@ -1748,8 +1754,16 @@ impl<'a, 't> Ancestor<'a, 't> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_ts_module_declaration(self) -> bool {
|
||||
matches!(self, Self::TSModuleDeclarationId(_) | Self::TSModuleDeclarationBody(_))
|
||||
pub fn is_ts_external_module_declaration(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::TSExternalModuleDeclarationId(_) | Self::TSExternalModuleDeclarationBody(_)
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_ts_namespace_declaration(self) -> bool {
|
||||
matches!(self, Self::TSNamespaceDeclarationId(_) | Self::TSNamespaceDeclarationBody(_))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -2230,13 +2244,8 @@ impl<'a, 't> Ancestor<'a, 't> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_parent_of_ts_module_declaration_name(self) -> bool {
|
||||
matches!(self, Self::TSModuleDeclarationId(_))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_parent_of_ts_module_declaration_body(self) -> bool {
|
||||
matches!(self, Self::TSModuleDeclarationBody(_))
|
||||
pub fn is_parent_of_ts_namespace_declaration_body(self) -> bool {
|
||||
matches!(self, Self::TSNamespaceDeclarationBody(_))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -2517,8 +2526,10 @@ impl<'a, 't> GetAddress for Ancestor<'a, 't> {
|
||||
Self::TSInterfaceHeritageTypeArguments(a) => a.address(),
|
||||
Self::TSTypePredicateParameterName(a) => a.address(),
|
||||
Self::TSTypePredicateTypeAnnotation(a) => a.address(),
|
||||
Self::TSModuleDeclarationId(a) => a.address(),
|
||||
Self::TSModuleDeclarationBody(a) => a.address(),
|
||||
Self::TSExternalModuleDeclarationId(a) => a.address(),
|
||||
Self::TSExternalModuleDeclarationBody(a) => a.address(),
|
||||
Self::TSNamespaceDeclarationId(a) => a.address(),
|
||||
Self::TSNamespaceDeclarationBody(a) => a.address(),
|
||||
Self::TSGlobalDeclarationBody(a) => a.address(),
|
||||
Self::TSModuleBlockDirectives(a) => a.address(),
|
||||
Self::TSModuleBlockBody(a) => a.address(),
|
||||
@@ -16245,71 +16256,68 @@ impl<'a, 't> GetAddress for TSTypePredicateWithoutTypeAnnotation<'a, 't> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_NODE_ID: usize =
|
||||
offset_of!(TSModuleDeclaration, node_id);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_SPAN: usize = offset_of!(TSModuleDeclaration, span);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_ID: usize = offset_of!(TSModuleDeclaration, id);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_BODY: usize = offset_of!(TSModuleDeclaration, body);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_KIND: usize = offset_of!(TSModuleDeclaration, kind);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_DECLARE: usize =
|
||||
offset_of!(TSModuleDeclaration, declare);
|
||||
pub(crate) const OFFSET_TS_MODULE_DECLARATION_SCOPE_ID: usize =
|
||||
offset_of!(TSModuleDeclaration, scope_id);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_NODE_ID: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, node_id);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SPAN: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, span);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_ID: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, id);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_BODY: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, body);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_DECLARE: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, declare);
|
||||
pub(crate) const OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SCOPE_ID: usize =
|
||||
offset_of!(TSExternalModuleDeclaration, scope_id);
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TSModuleDeclarationWithoutId<'a, 't>(
|
||||
pub(crate) *const TSModuleDeclaration<'a>,
|
||||
pub struct TSExternalModuleDeclarationWithoutId<'a, 't>(
|
||||
pub(crate) *const TSExternalModuleDeclaration<'a>,
|
||||
pub(crate) PhantomData<&'t ()>,
|
||||
);
|
||||
|
||||
impl<'a, 't> TSModuleDeclarationWithoutId<'a, 't> {
|
||||
impl<'a, 't> TSExternalModuleDeclarationWithoutId<'a, 't> {
|
||||
#[inline]
|
||||
pub fn node_id(self) -> &'t Cell<NodeId> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_NODE_ID)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_NODE_ID)
|
||||
as *const Cell<NodeId>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(self) -> &'t Span {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_SPAN) as *const Span) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn body(self) -> &'t Option<TSModuleDeclarationBody<'a>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_BODY)
|
||||
as *const Option<TSModuleDeclarationBody<'a>>)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SPAN) as *const Span)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(self) -> &'t TSModuleDeclarationKind {
|
||||
pub fn body(self) -> &'t Option<ArenaBox<'a, TSModuleBlock<'a>>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_KIND)
|
||||
as *const TSModuleDeclarationKind)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_BODY)
|
||||
as *const Option<ArenaBox<'a, TSModuleBlock<'a>>>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn declare(self) -> &'t bool {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_DECLARE) as *const bool)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_DECLARE)
|
||||
as *const bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_SCOPE_ID)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SCOPE_ID)
|
||||
as *const Cell<Option<ScopeId>>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 't> GetAddress for TSModuleDeclarationWithoutId<'a, 't> {
|
||||
impl<'a, 't> GetAddress for TSExternalModuleDeclarationWithoutId<'a, 't> {
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
unsafe { Address::from_ptr(self.0) }
|
||||
@@ -16318,58 +16326,191 @@ impl<'a, 't> GetAddress for TSModuleDeclarationWithoutId<'a, 't> {
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TSModuleDeclarationWithoutBody<'a, 't>(
|
||||
pub(crate) *const TSModuleDeclaration<'a>,
|
||||
pub struct TSExternalModuleDeclarationWithoutBody<'a, 't>(
|
||||
pub(crate) *const TSExternalModuleDeclaration<'a>,
|
||||
pub(crate) PhantomData<&'t ()>,
|
||||
);
|
||||
|
||||
impl<'a, 't> TSModuleDeclarationWithoutBody<'a, 't> {
|
||||
impl<'a, 't> TSExternalModuleDeclarationWithoutBody<'a, 't> {
|
||||
#[inline]
|
||||
pub fn node_id(self) -> &'t Cell<NodeId> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_NODE_ID)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_NODE_ID)
|
||||
as *const Cell<NodeId>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(self) -> &'t Span {
|
||||
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_SPAN) as *const Span) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(self) -> &'t TSModuleDeclarationName<'a> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_ID)
|
||||
as *const TSModuleDeclarationName<'a>)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SPAN) as *const Span)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(self) -> &'t TSModuleDeclarationKind {
|
||||
pub fn id(self) -> &'t StringLiteral<'a> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_KIND)
|
||||
as *const TSModuleDeclarationKind)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_ID)
|
||||
as *const StringLiteral<'a>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn declare(self) -> &'t bool {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_DECLARE) as *const bool)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_DECLARE)
|
||||
as *const bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_MODULE_DECLARATION_SCOPE_ID)
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SCOPE_ID)
|
||||
as *const Cell<Option<ScopeId>>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 't> GetAddress for TSModuleDeclarationWithoutBody<'a, 't> {
|
||||
impl<'a, 't> GetAddress for TSExternalModuleDeclarationWithoutBody<'a, 't> {
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
unsafe { Address::from_ptr(self.0) }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_NODE_ID: usize =
|
||||
offset_of!(TSNamespaceDeclaration, node_id);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_SPAN: usize =
|
||||
offset_of!(TSNamespaceDeclaration, span);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_ID: usize = offset_of!(TSNamespaceDeclaration, id);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_BODY: usize =
|
||||
offset_of!(TSNamespaceDeclaration, body);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_KIND: usize =
|
||||
offset_of!(TSNamespaceDeclaration, kind);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_DECLARE: usize =
|
||||
offset_of!(TSNamespaceDeclaration, declare);
|
||||
pub(crate) const OFFSET_TS_NAMESPACE_DECLARATION_SCOPE_ID: usize =
|
||||
offset_of!(TSNamespaceDeclaration, scope_id);
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TSNamespaceDeclarationWithoutId<'a, 't>(
|
||||
pub(crate) *const TSNamespaceDeclaration<'a>,
|
||||
pub(crate) PhantomData<&'t ()>,
|
||||
);
|
||||
|
||||
impl<'a, 't> TSNamespaceDeclarationWithoutId<'a, 't> {
|
||||
#[inline]
|
||||
pub fn node_id(self) -> &'t Cell<NodeId> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_NODE_ID)
|
||||
as *const Cell<NodeId>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(self) -> &'t Span {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_SPAN) as *const Span)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn body(self) -> &'t TSNamespaceDeclarationBody<'a> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_BODY)
|
||||
as *const TSNamespaceDeclarationBody<'a>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(self) -> &'t TSNamespaceDeclarationKind {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_KIND)
|
||||
as *const TSNamespaceDeclarationKind)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn declare(self) -> &'t bool {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_DECLARE) as *const bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_SCOPE_ID)
|
||||
as *const Cell<Option<ScopeId>>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 't> GetAddress for TSNamespaceDeclarationWithoutId<'a, 't> {
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
unsafe { Address::from_ptr(self.0) }
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TSNamespaceDeclarationWithoutBody<'a, 't>(
|
||||
pub(crate) *const TSNamespaceDeclaration<'a>,
|
||||
pub(crate) PhantomData<&'t ()>,
|
||||
);
|
||||
|
||||
impl<'a, 't> TSNamespaceDeclarationWithoutBody<'a, 't> {
|
||||
#[inline]
|
||||
pub fn node_id(self) -> &'t Cell<NodeId> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_NODE_ID)
|
||||
as *const Cell<NodeId>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(self) -> &'t Span {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_SPAN) as *const Span)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(self) -> &'t BindingIdentifier<'a> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_ID)
|
||||
as *const BindingIdentifier<'a>)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn kind(self) -> &'t TSNamespaceDeclarationKind {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_KIND)
|
||||
as *const TSNamespaceDeclarationKind)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn declare(self) -> &'t bool {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_DECLARE) as *const bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn scope_id(self) -> &'t Cell<Option<ScopeId>> {
|
||||
unsafe {
|
||||
&*((self.0 as *const u8).add(OFFSET_TS_NAMESPACE_DECLARATION_SCOPE_ID)
|
||||
as *const Cell<Option<ScopeId>>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 't> GetAddress for TSNamespaceDeclarationWithoutBody<'a, 't> {
|
||||
#[inline]
|
||||
fn address(&self) -> Address {
|
||||
unsafe { Address::from_ptr(self.0) }
|
||||
|
||||
@@ -623,7 +623,10 @@ impl<'a> Visit<'a> for ChildScopeCollector {
|
||||
Statement::TSTypeAliasDeclaration(it) => self.visit_ts_type_alias_declaration(it),
|
||||
Statement::TSInterfaceDeclaration(it) => self.visit_ts_interface_declaration(it),
|
||||
Statement::TSEnumDeclaration(it) => self.visit_ts_enum_declaration(it),
|
||||
Statement::TSModuleDeclaration(it) => self.visit_ts_module_declaration(it),
|
||||
Statement::TSExternalModuleDeclaration(it) => {
|
||||
self.visit_ts_external_module_declaration(it)
|
||||
}
|
||||
Statement::TSNamespaceDeclaration(it) => self.visit_ts_namespace_declaration(it),
|
||||
Statement::TSGlobalDeclaration(it) => self.visit_ts_global_declaration(it),
|
||||
Statement::ExportDefaultDeclaration(it) => self.visit_export_default_declaration(it),
|
||||
Statement::ExportDeclaration(it) => self.visit_export_declaration(it),
|
||||
@@ -670,7 +673,10 @@ impl<'a> Visit<'a> for ChildScopeCollector {
|
||||
Declaration::TSTypeAliasDeclaration(it) => self.visit_ts_type_alias_declaration(it),
|
||||
Declaration::TSInterfaceDeclaration(it) => self.visit_ts_interface_declaration(it),
|
||||
Declaration::TSEnumDeclaration(it) => self.visit_ts_enum_declaration(it),
|
||||
Declaration::TSModuleDeclaration(it) => self.visit_ts_module_declaration(it),
|
||||
Declaration::TSExternalModuleDeclaration(it) => {
|
||||
self.visit_ts_external_module_declaration(it)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(it) => self.visit_ts_namespace_declaration(it),
|
||||
Declaration::TSGlobalDeclaration(it) => self.visit_ts_global_declaration(it),
|
||||
_ => {
|
||||
// Remaining variants do not contain scopes:
|
||||
@@ -1948,13 +1954,13 @@ impl<'a> Visit<'a> for ChildScopeCollector {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ts_module_declaration(&mut self, it: &TSModuleDeclaration<'a>) {
|
||||
fn visit_ts_external_module_declaration(&mut self, it: &TSExternalModuleDeclaration<'a>) {
|
||||
self.add_scope(&it.scope_id);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn visit_ts_module_declaration_name(&mut self, it: &TSModuleDeclarationName<'a>) {
|
||||
// Enum does not contain a scope. Halt traversal.
|
||||
#[inline]
|
||||
fn visit_ts_namespace_declaration(&mut self, it: &TSNamespaceDeclaration<'a>) {
|
||||
self.add_scope(&it.scope_id);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -2725,46 +2725,46 @@ pub trait Traverse<'a, State> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn enter_ts_module_declaration(
|
||||
fn enter_ts_external_module_declaration(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclaration<'a>,
|
||||
node: &mut TSExternalModuleDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
}
|
||||
#[inline]
|
||||
fn exit_ts_module_declaration(
|
||||
fn exit_ts_external_module_declaration(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclaration<'a>,
|
||||
node: &mut TSExternalModuleDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn enter_ts_module_declaration_name(
|
||||
fn enter_ts_namespace_declaration(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclarationName<'a>,
|
||||
node: &mut TSNamespaceDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
}
|
||||
#[inline]
|
||||
fn exit_ts_module_declaration_name(
|
||||
fn exit_ts_namespace_declaration(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclarationName<'a>,
|
||||
node: &mut TSNamespaceDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn enter_ts_module_declaration_body(
|
||||
fn enter_ts_namespace_declaration_body(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclarationBody<'a>,
|
||||
node: &mut TSNamespaceDeclarationBody<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
}
|
||||
#[inline]
|
||||
fn exit_ts_module_declaration_body(
|
||||
fn exit_ts_namespace_declaration_body(
|
||||
&mut self,
|
||||
node: &mut TSModuleDeclarationBody<'a>,
|
||||
node: &mut TSNamespaceDeclarationBody<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -1374,7 +1374,8 @@ unsafe fn walk_statement<'a, State, Tr: Traverse<'a, State>>(
|
||||
| Statement::TSTypeAliasDeclaration(_)
|
||||
| Statement::TSInterfaceDeclaration(_)
|
||||
| Statement::TSEnumDeclaration(_)
|
||||
| Statement::TSModuleDeclaration(_)
|
||||
| Statement::TSExternalModuleDeclaration(_)
|
||||
| Statement::TSNamespaceDeclaration(_)
|
||||
| Statement::TSGlobalDeclaration(_)
|
||||
| Statement::TSImportEqualsDeclaration(_) => {
|
||||
walk_declaration(traverser, node as *mut _, ctx)
|
||||
@@ -1471,8 +1472,11 @@ unsafe fn walk_declaration<'a, State, Tr: Traverse<'a, State>>(
|
||||
Declaration::TSEnumDeclaration(node) => {
|
||||
walk_ts_enum_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
Declaration::TSModuleDeclaration(node) => {
|
||||
walk_ts_module_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
Declaration::TSExternalModuleDeclaration(node) => {
|
||||
walk_ts_external_module_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
Declaration::TSNamespaceDeclaration(node) => {
|
||||
walk_ts_namespace_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
Declaration::TSGlobalDeclaration(node) => {
|
||||
walk_ts_global_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
@@ -5102,77 +5106,101 @@ unsafe fn walk_ts_type_predicate_name<'a, State, Tr: Traverse<'a, State>>(
|
||||
traverser.exit_ts_type_predicate_name(&mut *node, ctx);
|
||||
}
|
||||
|
||||
unsafe fn walk_ts_module_declaration<'a, State, Tr: Traverse<'a, State>>(
|
||||
unsafe fn walk_ts_external_module_declaration<'a, State, Tr: Traverse<'a, State>>(
|
||||
traverser: &mut Tr,
|
||||
node: *mut TSModuleDeclaration<'a>,
|
||||
node: *mut TSExternalModuleDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
traverser.enter_ts_module_declaration(&mut *node, ctx);
|
||||
let pop_token = ctx.push_stack(Ancestor::TSModuleDeclarationId(
|
||||
ancestor::TSModuleDeclarationWithoutId(node, PhantomData),
|
||||
traverser.enter_ts_external_module_declaration(&mut *node, ctx);
|
||||
let pop_token = ctx.push_stack(Ancestor::TSExternalModuleDeclarationId(
|
||||
ancestor::TSExternalModuleDeclarationWithoutId(node, PhantomData),
|
||||
));
|
||||
walk_ts_module_declaration_name(
|
||||
walk_string_literal(
|
||||
traverser,
|
||||
(node as *mut u8).add(ancestor::OFFSET_TS_MODULE_DECLARATION_ID)
|
||||
as *mut TSModuleDeclarationName,
|
||||
(node as *mut u8).add(ancestor::OFFSET_TS_EXTERNAL_MODULE_DECLARATION_ID)
|
||||
as *mut StringLiteral,
|
||||
ctx,
|
||||
);
|
||||
let previous_scope_id = ctx.current_scope_id();
|
||||
let current_scope_id =
|
||||
(*((node as *mut u8).add(ancestor::OFFSET_TS_MODULE_DECLARATION_SCOPE_ID)
|
||||
as *mut Cell<Option<ScopeId>>))
|
||||
.get()
|
||||
.unwrap();
|
||||
let current_scope_id = (*((node as *mut u8)
|
||||
.add(ancestor::OFFSET_TS_EXTERNAL_MODULE_DECLARATION_SCOPE_ID)
|
||||
as *mut Cell<Option<ScopeId>>))
|
||||
.get()
|
||||
.unwrap();
|
||||
ctx.set_current_scope_id(current_scope_id);
|
||||
let previous_hoist_scope_id = ctx.current_hoist_scope_id();
|
||||
ctx.set_current_hoist_scope_id(current_scope_id);
|
||||
let previous_block_scope_id = ctx.current_block_scope_id();
|
||||
ctx.set_current_block_scope_id(current_scope_id);
|
||||
if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_TS_MODULE_DECLARATION_BODY)
|
||||
as *mut Option<TSModuleDeclarationBody>)
|
||||
if let Some(field) = &mut *((node as *mut u8)
|
||||
.add(ancestor::OFFSET_TS_EXTERNAL_MODULE_DECLARATION_BODY)
|
||||
as *mut Option<ArenaBox<TSModuleBlock>>)
|
||||
{
|
||||
ctx.retag_stack(AncestorType::TSModuleDeclarationBody);
|
||||
walk_ts_module_declaration_body(traverser, field as *mut _, ctx);
|
||||
ctx.retag_stack(AncestorType::TSExternalModuleDeclarationBody);
|
||||
walk_ts_module_block(traverser, (&mut **field) as *mut _, ctx);
|
||||
}
|
||||
ctx.pop_stack(pop_token);
|
||||
ctx.set_current_scope_id(previous_scope_id);
|
||||
ctx.set_current_hoist_scope_id(previous_hoist_scope_id);
|
||||
ctx.set_current_block_scope_id(previous_block_scope_id);
|
||||
traverser.exit_ts_module_declaration(&mut *node, ctx);
|
||||
traverser.exit_ts_external_module_declaration(&mut *node, ctx);
|
||||
}
|
||||
|
||||
unsafe fn walk_ts_module_declaration_name<'a, State, Tr: Traverse<'a, State>>(
|
||||
unsafe fn walk_ts_namespace_declaration<'a, State, Tr: Traverse<'a, State>>(
|
||||
traverser: &mut Tr,
|
||||
node: *mut TSModuleDeclarationName<'a>,
|
||||
node: *mut TSNamespaceDeclaration<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
traverser.enter_ts_module_declaration_name(&mut *node, ctx);
|
||||
match &mut *node {
|
||||
TSModuleDeclarationName::Identifier(node) => {
|
||||
walk_binding_identifier(traverser, node as *mut _, ctx)
|
||||
}
|
||||
TSModuleDeclarationName::StringLiteral(node) => {
|
||||
walk_string_literal(traverser, node as *mut _, ctx)
|
||||
}
|
||||
}
|
||||
traverser.exit_ts_module_declaration_name(&mut *node, ctx);
|
||||
traverser.enter_ts_namespace_declaration(&mut *node, ctx);
|
||||
let pop_token = ctx.push_stack(Ancestor::TSNamespaceDeclarationId(
|
||||
ancestor::TSNamespaceDeclarationWithoutId(node, PhantomData),
|
||||
));
|
||||
walk_binding_identifier(
|
||||
traverser,
|
||||
(node as *mut u8).add(ancestor::OFFSET_TS_NAMESPACE_DECLARATION_ID)
|
||||
as *mut BindingIdentifier,
|
||||
ctx,
|
||||
);
|
||||
let previous_scope_id = ctx.current_scope_id();
|
||||
let current_scope_id = (*((node as *mut u8)
|
||||
.add(ancestor::OFFSET_TS_NAMESPACE_DECLARATION_SCOPE_ID)
|
||||
as *mut Cell<Option<ScopeId>>))
|
||||
.get()
|
||||
.unwrap();
|
||||
ctx.set_current_scope_id(current_scope_id);
|
||||
let previous_hoist_scope_id = ctx.current_hoist_scope_id();
|
||||
ctx.set_current_hoist_scope_id(current_scope_id);
|
||||
let previous_block_scope_id = ctx.current_block_scope_id();
|
||||
ctx.set_current_block_scope_id(current_scope_id);
|
||||
ctx.retag_stack(AncestorType::TSNamespaceDeclarationBody);
|
||||
walk_ts_namespace_declaration_body(
|
||||
traverser,
|
||||
(node as *mut u8).add(ancestor::OFFSET_TS_NAMESPACE_DECLARATION_BODY)
|
||||
as *mut TSNamespaceDeclarationBody,
|
||||
ctx,
|
||||
);
|
||||
ctx.pop_stack(pop_token);
|
||||
ctx.set_current_scope_id(previous_scope_id);
|
||||
ctx.set_current_hoist_scope_id(previous_hoist_scope_id);
|
||||
ctx.set_current_block_scope_id(previous_block_scope_id);
|
||||
traverser.exit_ts_namespace_declaration(&mut *node, ctx);
|
||||
}
|
||||
|
||||
unsafe fn walk_ts_module_declaration_body<'a, State, Tr: Traverse<'a, State>>(
|
||||
unsafe fn walk_ts_namespace_declaration_body<'a, State, Tr: Traverse<'a, State>>(
|
||||
traverser: &mut Tr,
|
||||
node: *mut TSModuleDeclarationBody<'a>,
|
||||
node: *mut TSNamespaceDeclarationBody<'a>,
|
||||
ctx: &mut TraverseCtx<'a, State>,
|
||||
) {
|
||||
traverser.enter_ts_module_declaration_body(&mut *node, ctx);
|
||||
traverser.enter_ts_namespace_declaration_body(&mut *node, ctx);
|
||||
match &mut *node {
|
||||
TSModuleDeclarationBody::TSModuleDeclaration(node) => {
|
||||
walk_ts_module_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
TSNamespaceDeclarationBody::TSNamespaceDeclaration(node) => {
|
||||
walk_ts_namespace_declaration(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
TSModuleDeclarationBody::TSModuleBlock(node) => {
|
||||
TSNamespaceDeclarationBody::TSModuleBlock(node) => {
|
||||
walk_ts_module_block(traverser, (&mut **node) as *mut _, ctx)
|
||||
}
|
||||
}
|
||||
traverser.exit_ts_module_declaration_body(&mut *node, ctx);
|
||||
traverser.exit_ts_namespace_declaration_body(&mut *node, ctx);
|
||||
}
|
||||
|
||||
unsafe fn walk_ts_global_declaration<'a, State, Tr: Traverse<'a, State>>(
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
use oxc_ast::ast::{
|
||||
CallExpression, Declaration, Expression, ImportExpression, Program as AstProgram, Statement,
|
||||
TSImportType, TSModuleDeclarationBody, TSModuleDeclarationName, TSModuleReference,
|
||||
TSImportType, TSModuleReference,
|
||||
};
|
||||
use oxc_ast_visit::{Visit, walk};
|
||||
use oxc_span::GetSpan;
|
||||
@@ -198,10 +198,8 @@ impl Collector {
|
||||
self.add_static(decl.source.span.start, &decl.source.value, true);
|
||||
}
|
||||
}
|
||||
Statement::TSModuleDeclaration(decl) => {
|
||||
// Only string-named ambient modules matter here (`declare global` has no module
|
||||
// name to resolve; tsgo drops it at resolution time).
|
||||
let TSModuleDeclarationName::StringLiteral(name) = &decl.id else { return };
|
||||
Statement::TSExternalModuleDeclaration(decl) => {
|
||||
let name = &decl.id;
|
||||
if !(in_ambient_module || decl.declare || self.is_declaration_file) {
|
||||
return;
|
||||
}
|
||||
@@ -215,7 +213,7 @@ impl Collector {
|
||||
} else if !in_ambient_module {
|
||||
// A top-level ambient module declaration in a script file *declares* the
|
||||
// module — nothing to resolve, but its body may reference other modules.
|
||||
if let Some(TSModuleDeclarationBody::TSModuleBlock(block)) = &decl.body {
|
||||
if let Some(block) = &decl.body {
|
||||
for statement in &block.body {
|
||||
self.collect_module_references(statement, true);
|
||||
}
|
||||
|
||||
@@ -1172,10 +1172,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1245,10 +1247,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -3810,26 +3814,31 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
declare = deserializeBool(pos + 72),
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
@@ -3839,77 +3848,63 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") node.id = id;
|
||||
},
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") node.id = id;
|
||||
else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier")
|
||||
node.id = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
};
|
||||
else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier")
|
||||
node.id = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
};
|
||||
else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let right = innerId.left;
|
||||
innerId.left = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: right.end,
|
||||
};
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
} else body = null;
|
||||
let right = innerId.left;
|
||||
innerId.left = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: right.end,
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5203,8 +5198,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -5893,14 +5892,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
@@ -1284,10 +1284,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1364,10 +1366,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -4245,29 +4249,37 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
declare = deserializeBool(pos + 72),
|
||||
previousParent = parent,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
node = parent = {
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = (parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
parent,
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node = parent = {
|
||||
});
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
body !== null && (body.parent = node);
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
previousParent = parent,
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = (parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
body,
|
||||
@@ -4277,91 +4289,77 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
start,
|
||||
end,
|
||||
parent,
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
}),
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: right.end,
|
||||
parent: innerId,
|
||||
};
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
} else body = null;
|
||||
let right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: right.end,
|
||||
parent: innerId,
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
}
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5726,8 +5724,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -6416,14 +6418,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
@@ -1287,10 +1287,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1368,10 +1370,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -4262,27 +4266,32 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
declare = deserializeBool(pos + 72),
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
range: [start, end],
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
@@ -4293,81 +4302,67 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
start,
|
||||
end,
|
||||
range: [start, end],
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") node.id = id;
|
||||
else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start, end;
|
||||
node.id = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
};
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let end,
|
||||
right = innerId.left;
|
||||
innerId.left = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
range: [start, end],
|
||||
};
|
||||
},
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") node.id = id;
|
||||
else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start, end;
|
||||
node.id = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
};
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
} else body = null;
|
||||
let end,
|
||||
right = innerId.left;
|
||||
innerId.left = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
range: [start, end],
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5761,8 +5756,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -6451,14 +6450,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
@@ -1398,10 +1398,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1486,10 +1488,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -4695,30 +4699,38 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
declare = deserializeBool(pos + 72),
|
||||
previousParent = parent,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
node = parent = {
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = (parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
range: [start, end],
|
||||
parent,
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node = parent = {
|
||||
});
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
body !== null && (body.parent = node);
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
previousParent = parent,
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = (parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
body,
|
||||
@@ -4729,96 +4741,82 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
end,
|
||||
range: [start, end],
|
||||
parent,
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start,
|
||||
end,
|
||||
outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let end,
|
||||
right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
}),
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start,
|
||||
end,
|
||||
outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
parent: innerId,
|
||||
};
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
} else body = null;
|
||||
let end,
|
||||
right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
range: [start, end],
|
||||
parent: innerId,
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
}
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6283,8 +6281,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -6973,14 +6975,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
@@ -1243,10 +1243,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1316,10 +1318,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -4104,26 +4108,31 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
declare = deserializeBool(pos + 72),
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
@@ -4133,77 +4142,63 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") node.id = id;
|
||||
},
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") node.id = id;
|
||||
else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier")
|
||||
node.id = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
};
|
||||
else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier")
|
||||
node.id = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
};
|
||||
else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let right = innerId.left;
|
||||
innerId.left = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: right.end,
|
||||
};
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
} else body = null;
|
||||
let right = innerId.left;
|
||||
innerId.left = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: right.end,
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5500,8 +5495,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -6206,14 +6205,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
@@ -1355,10 +1355,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1435,10 +1437,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -4569,29 +4573,37 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
declare = deserializeBool(pos + 72),
|
||||
previousParent = parent,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
node = parent = {
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = (parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
parent,
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node = parent = {
|
||||
});
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
body !== null && (body.parent = node);
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
previousParent = parent,
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = (parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
body,
|
||||
@@ -4601,91 +4613,77 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
start,
|
||||
end,
|
||||
parent,
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
}),
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: id.start,
|
||||
end: innerId.end,
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: right.end,
|
||||
parent: innerId,
|
||||
};
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
} else body = null;
|
||||
let right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: right.end,
|
||||
parent: innerId,
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
}
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6053,8 +6051,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -6759,14 +6761,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
@@ -1358,10 +1358,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1439,10 +1441,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -4584,27 +4588,32 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
declare = deserializeBool(pos + 72),
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
range: [start, end],
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
@@ -4615,81 +4624,67 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
start,
|
||||
end,
|
||||
range: [start, end],
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") node.id = id;
|
||||
else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start, end;
|
||||
node.id = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
};
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let end,
|
||||
right = innerId.left;
|
||||
innerId.left = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
range: [start, end],
|
||||
};
|
||||
},
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") node.id = id;
|
||||
else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start, end;
|
||||
node.id = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
};
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
} else body = null;
|
||||
let end,
|
||||
right = innerId.left;
|
||||
innerId.left = {
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
range: [start, end],
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6086,8 +6081,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -6792,14 +6791,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
@@ -1469,10 +1469,12 @@ function deserializeStatement(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
case 64:
|
||||
return deserializeBoxImportDeclaration(pos + 8);
|
||||
@@ -1557,10 +1559,12 @@ function deserializeDeclaration(pos) {
|
||||
case 37:
|
||||
return deserializeBoxTSEnumDeclaration(pos + 8);
|
||||
case 38:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSExternalModuleDeclaration(pos + 8);
|
||||
case 39:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 40:
|
||||
return deserializeBoxTSGlobalDeclaration(pos + 8);
|
||||
case 41:
|
||||
return deserializeBoxTSImportEqualsDeclaration(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for Declaration`);
|
||||
@@ -5047,30 +5051,38 @@ function deserializeTSTypePredicateName(pos) {
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclaration(pos) {
|
||||
let kind = deserializeTSModuleDeclarationKind(pos + 88),
|
||||
start = deserializeI32(pos),
|
||||
function deserializeTSExternalModuleDeclaration(pos) {
|
||||
let start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 89),
|
||||
node,
|
||||
declare = deserializeBool(pos + 72),
|
||||
previousParent = parent,
|
||||
body = deserializeOptionTSModuleDeclarationBody(pos + 72);
|
||||
if (body === null) {
|
||||
node = parent = {
|
||||
body = deserializeOptionBoxTSModuleBlock(pos + 64),
|
||||
node = (parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
// No `body` field
|
||||
kind,
|
||||
...(body !== null && { body }),
|
||||
kind: "module",
|
||||
declare,
|
||||
global: false,
|
||||
start,
|
||||
end,
|
||||
range: [start, end],
|
||||
parent,
|
||||
};
|
||||
node.id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
} else {
|
||||
node = parent = {
|
||||
});
|
||||
node.id = deserializeStringLiteral(pos + 16);
|
||||
body !== null && (body.parent = node);
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSNamespaceDeclaration(pos) {
|
||||
let kind = deserializeTSNamespaceDeclarationKind(pos + 64),
|
||||
start = deserializeI32(pos),
|
||||
end = deserializeI32(pos + 4),
|
||||
declare = deserializeBool(pos + 65),
|
||||
previousParent = parent,
|
||||
body = deserializeTSNamespaceDeclarationBody(pos + 48),
|
||||
node = (parent = {
|
||||
type: "TSModuleDeclaration",
|
||||
id: null,
|
||||
body,
|
||||
@@ -5081,96 +5093,82 @@ function deserializeTSModuleDeclaration(pos) {
|
||||
end,
|
||||
range: [start, end],
|
||||
parent,
|
||||
};
|
||||
let id = deserializeTSModuleDeclarationName(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start,
|
||||
end,
|
||||
outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with `id` of
|
||||
// this module on left, and previous `left` of innermost `TSQualifiedName` on right
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
let end,
|
||||
right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
}),
|
||||
id = deserializeBindingIdentifier(pos + 16);
|
||||
if (body.type === "TSModuleBlock") {
|
||||
node.id = id;
|
||||
body.parent = node;
|
||||
} else {
|
||||
let innerId = body.id;
|
||||
if (innerId.type === "Identifier") {
|
||||
let start,
|
||||
end,
|
||||
outerId =
|
||||
(node.id =
|
||||
parent =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
right: innerId,
|
||||
start: (start = id.start),
|
||||
end: (end = innerId.end),
|
||||
range: [start, end],
|
||||
parent: innerId,
|
||||
};
|
||||
parent: node,
|
||||
});
|
||||
id.parent = innerId.parent = outerId;
|
||||
} else {
|
||||
// Replace `left` of innermost `TSQualifiedName` with a nested `TSQualifiedName` with
|
||||
// `id` of this namespace on left, and previous `left` on right.
|
||||
node.id = innerId;
|
||||
innerId.parent = node;
|
||||
let { start } = id;
|
||||
for (;;) {
|
||||
innerId.start = innerId.range[0] = start;
|
||||
if (innerId.left.type === "Identifier") break;
|
||||
innerId = innerId.left;
|
||||
}
|
||||
if (Object.hasOwn(body, "body")) {
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
} else body = null;
|
||||
let end,
|
||||
right = innerId.left;
|
||||
id.parent =
|
||||
right.parent =
|
||||
innerId.left =
|
||||
{
|
||||
type: "TSQualifiedName",
|
||||
left: id,
|
||||
right,
|
||||
start,
|
||||
end: (end = right.end),
|
||||
range: [start, end],
|
||||
parent: innerId,
|
||||
};
|
||||
}
|
||||
body = body.body;
|
||||
node.body = body;
|
||||
body.parent = node;
|
||||
}
|
||||
parent = previousParent;
|
||||
return node;
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationKind(pos) {
|
||||
function deserializeTSNamespaceDeclarationKind(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationKind`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationName(pos) {
|
||||
function deserializeTSNamespaceDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBindingIdentifier(pos + 8);
|
||||
case 1:
|
||||
return deserializeStringLiteral(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function deserializeTSModuleDeclarationBody(pos) {
|
||||
switch (uint8[pos]) {
|
||||
case 0:
|
||||
return deserializeBoxTSModuleDeclaration(pos + 8);
|
||||
return deserializeBoxTSNamespaceDeclaration(pos + 8);
|
||||
case 1:
|
||||
return deserializeBoxTSModuleBlock(pos + 8);
|
||||
default:
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSModuleDeclarationBody`);
|
||||
throw Error(`Unexpected discriminant ${uint8[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6638,8 +6636,12 @@ function deserializeBoxTSEnumDeclaration(pos) {
|
||||
return deserializeTSEnumDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleDeclaration(pos) {
|
||||
return deserializeTSModuleDeclaration(int32[pos >> 2]);
|
||||
function deserializeBoxTSExternalModuleDeclaration(pos) {
|
||||
return deserializeTSExternalModuleDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSNamespaceDeclaration(pos) {
|
||||
return deserializeTSNamespaceDeclaration(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeBoxTSGlobalDeclaration(pos) {
|
||||
@@ -7344,14 +7346,16 @@ function deserializeBoxTSMethodSignature(pos) {
|
||||
return deserializeTSMethodSignature(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionTSModuleDeclarationBody(pos) {
|
||||
return uint8[pos] === 2 ? null : deserializeTSModuleDeclarationBody(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSModuleBlock(pos) {
|
||||
return deserializeTSModuleBlock(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
function deserializeOptionBoxTSModuleBlock(pos) {
|
||||
return int32[pos >> 2] === 0 && int32[(pos >> 2) + 1] === 0
|
||||
? null
|
||||
: deserializeBoxTSModuleBlock(pos);
|
||||
}
|
||||
|
||||
function deserializeBoxTSTypeParameter(pos) {
|
||||
return deserializeTSTypeParameter(int32[pos >> 2]);
|
||||
}
|
||||
|
||||
@@ -2678,10 +2678,12 @@ function constructStatement(pos, ast) {
|
||||
case 37:
|
||||
return constructBoxTSEnumDeclaration(pos + 8, ast);
|
||||
case 38:
|
||||
return constructBoxTSModuleDeclaration(pos + 8, ast);
|
||||
return constructBoxTSExternalModuleDeclaration(pos + 8, ast);
|
||||
case 39:
|
||||
return constructBoxTSGlobalDeclaration(pos + 8, ast);
|
||||
return constructBoxTSNamespaceDeclaration(pos + 8, ast);
|
||||
case 40:
|
||||
return constructBoxTSGlobalDeclaration(pos + 8, ast);
|
||||
case 41:
|
||||
return constructBoxTSImportEqualsDeclaration(pos + 8, ast);
|
||||
case 64:
|
||||
return constructBoxImportDeclaration(pos + 8, ast);
|
||||
@@ -2869,10 +2871,12 @@ function constructDeclaration(pos, ast) {
|
||||
case 37:
|
||||
return constructBoxTSEnumDeclaration(pos + 8, ast);
|
||||
case 38:
|
||||
return constructBoxTSModuleDeclaration(pos + 8, ast);
|
||||
return constructBoxTSExternalModuleDeclaration(pos + 8, ast);
|
||||
case 39:
|
||||
return constructBoxTSGlobalDeclaration(pos + 8, ast);
|
||||
return constructBoxTSNamespaceDeclaration(pos + 8, ast);
|
||||
case 40:
|
||||
return constructBoxTSGlobalDeclaration(pos + 8, ast);
|
||||
case 41:
|
||||
return constructBoxTSImportEqualsDeclaration(pos + 8, ast);
|
||||
default:
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for Declaration`);
|
||||
@@ -10557,8 +10561,8 @@ function constructTSTypePredicateName(pos, ast) {
|
||||
}
|
||||
}
|
||||
|
||||
export class TSModuleDeclaration {
|
||||
type = "TSModuleDeclaration";
|
||||
export class TSExternalModuleDeclaration {
|
||||
type = "TSExternalModuleDeclaration";
|
||||
#internal;
|
||||
|
||||
constructor(pos, ast) {
|
||||
@@ -10584,27 +10588,85 @@ export class TSModuleDeclaration {
|
||||
|
||||
get id() {
|
||||
const internal = this.#internal;
|
||||
return constructTSModuleDeclarationName(internal.pos + 16, internal.ast);
|
||||
return new StringLiteral(internal.pos + 16, internal.ast);
|
||||
}
|
||||
|
||||
get body() {
|
||||
const internal = this.#internal;
|
||||
return constructOptionTSModuleDeclarationBody(internal.pos + 72, internal.ast);
|
||||
}
|
||||
|
||||
get kind() {
|
||||
const internal = this.#internal;
|
||||
return constructTSModuleDeclarationKind(internal.pos + 88, internal.ast);
|
||||
return constructOptionBoxTSModuleBlock(internal.pos + 64, internal.ast);
|
||||
}
|
||||
|
||||
get declare() {
|
||||
const internal = this.#internal;
|
||||
return constructBool(internal.pos + 89, internal.ast);
|
||||
return constructBool(internal.pos + 72, internal.ast);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
type: "TSModuleDeclaration",
|
||||
type: "TSExternalModuleDeclaration",
|
||||
start: this.start,
|
||||
end: this.end,
|
||||
id: this.id,
|
||||
body: this.body,
|
||||
declare: this.declare,
|
||||
};
|
||||
}
|
||||
|
||||
[inspectSymbol]() {
|
||||
return Object.setPrototypeOf(this.toJSON(), DebugTSExternalModuleDeclaration.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
const DebugTSExternalModuleDeclaration = class TSExternalModuleDeclaration {};
|
||||
|
||||
export class TSNamespaceDeclaration {
|
||||
type = "TSNamespaceDeclaration";
|
||||
#internal;
|
||||
|
||||
constructor(pos, ast) {
|
||||
if (ast?.token !== TOKEN) constructorError();
|
||||
|
||||
const { nodes } = ast;
|
||||
const cached = nodes.get(pos);
|
||||
if (cached !== void 0) return cached;
|
||||
|
||||
this.#internal = { pos, ast };
|
||||
nodes.set(pos, this);
|
||||
}
|
||||
|
||||
get start() {
|
||||
const internal = this.#internal;
|
||||
return constructI32(internal.pos, internal.ast);
|
||||
}
|
||||
|
||||
get end() {
|
||||
const internal = this.#internal;
|
||||
return constructI32(internal.pos + 4, internal.ast);
|
||||
}
|
||||
|
||||
get id() {
|
||||
const internal = this.#internal;
|
||||
return new BindingIdentifier(internal.pos + 16, internal.ast);
|
||||
}
|
||||
|
||||
get body() {
|
||||
const internal = this.#internal;
|
||||
return constructTSNamespaceDeclarationBody(internal.pos + 48, internal.ast);
|
||||
}
|
||||
|
||||
get kind() {
|
||||
const internal = this.#internal;
|
||||
return constructTSNamespaceDeclarationKind(internal.pos + 64, internal.ast);
|
||||
}
|
||||
|
||||
get declare() {
|
||||
const internal = this.#internal;
|
||||
return constructBool(internal.pos + 65, internal.ast);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
type: "TSNamespaceDeclaration",
|
||||
start: this.start,
|
||||
end: this.end,
|
||||
id: this.id,
|
||||
@@ -10615,42 +10677,31 @@ export class TSModuleDeclaration {
|
||||
}
|
||||
|
||||
[inspectSymbol]() {
|
||||
return Object.setPrototypeOf(this.toJSON(), DebugTSModuleDeclaration.prototype);
|
||||
return Object.setPrototypeOf(this.toJSON(), DebugTSNamespaceDeclaration.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
const DebugTSModuleDeclaration = class TSModuleDeclaration {};
|
||||
const DebugTSNamespaceDeclaration = class TSNamespaceDeclaration {};
|
||||
|
||||
function constructTSModuleDeclarationKind(pos, ast) {
|
||||
function constructTSNamespaceDeclarationKind(pos, ast) {
|
||||
switch (ast.buffer[pos]) {
|
||||
case 0:
|
||||
return "module";
|
||||
case 1:
|
||||
return "namespace";
|
||||
default:
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleDeclarationKind`);
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSNamespaceDeclarationKind`);
|
||||
}
|
||||
}
|
||||
|
||||
function constructTSModuleDeclarationName(pos, ast) {
|
||||
function constructTSNamespaceDeclarationBody(pos, ast) {
|
||||
switch (ast.buffer[pos]) {
|
||||
case 0:
|
||||
return new BindingIdentifier(pos + 8, ast);
|
||||
case 1:
|
||||
return new StringLiteral(pos + 8, ast);
|
||||
default:
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleDeclarationName`);
|
||||
}
|
||||
}
|
||||
|
||||
function constructTSModuleDeclarationBody(pos, ast) {
|
||||
switch (ast.buffer[pos]) {
|
||||
case 0:
|
||||
return constructBoxTSModuleDeclaration(pos + 8, ast);
|
||||
return constructBoxTSNamespaceDeclaration(pos + 8, ast);
|
||||
case 1:
|
||||
return constructBoxTSModuleBlock(pos + 8, ast);
|
||||
default:
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleDeclarationBody`);
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13318,8 +13369,12 @@ function constructBoxTSEnumDeclaration(pos, ast) {
|
||||
return new TSEnumDeclaration(ast.buffer.int32[pos >> 2], ast);
|
||||
}
|
||||
|
||||
function constructBoxTSModuleDeclaration(pos, ast) {
|
||||
return new TSModuleDeclaration(ast.buffer.int32[pos >> 2], ast);
|
||||
function constructBoxTSExternalModuleDeclaration(pos, ast) {
|
||||
return new TSExternalModuleDeclaration(ast.buffer.int32[pos >> 2], ast);
|
||||
}
|
||||
|
||||
function constructBoxTSNamespaceDeclaration(pos, ast) {
|
||||
return new TSNamespaceDeclaration(ast.buffer.int32[pos >> 2], ast);
|
||||
}
|
||||
|
||||
function constructBoxTSGlobalDeclaration(pos, ast) {
|
||||
@@ -13956,15 +14011,15 @@ function constructBoxTSMethodSignature(pos, ast) {
|
||||
return new TSMethodSignature(ast.buffer.int32[pos >> 2], ast);
|
||||
}
|
||||
|
||||
function constructOptionTSModuleDeclarationBody(pos, ast) {
|
||||
if (ast.buffer[pos] === 2) return null;
|
||||
return constructTSModuleDeclarationBody(pos, ast);
|
||||
}
|
||||
|
||||
function constructBoxTSModuleBlock(pos, ast) {
|
||||
return new TSModuleBlock(ast.buffer.int32[pos >> 2], ast);
|
||||
}
|
||||
|
||||
function constructOptionBoxTSModuleBlock(pos, ast) {
|
||||
if (ast.buffer.int32[pos >> 2] === 0 && ast.buffer.int32[(pos >> 2) + 1] === 0) return null;
|
||||
return constructBoxTSModuleBlock(pos, ast);
|
||||
}
|
||||
|
||||
function constructBoxTSTypeParameter(pos, ast) {
|
||||
return new TSTypeParameter(ast.buffer.int32[pos >> 2], ast);
|
||||
}
|
||||
|
||||
@@ -164,31 +164,32 @@ export const NODE_TYPE_IDS_MAP = new Map([
|
||||
["TSIndexSignatureName", 156],
|
||||
["TSInterfaceHeritage", 157],
|
||||
["TSTypePredicate", 158],
|
||||
["TSModuleDeclaration", 159],
|
||||
["TSGlobalDeclaration", 160],
|
||||
["TSModuleBlock", 161],
|
||||
["TSTypeLiteral", 162],
|
||||
["TSInferType", 163],
|
||||
["TSTypeQuery", 164],
|
||||
["TSImportType", 165],
|
||||
["TSImportTypeQualifiedName", 166],
|
||||
["TSFunctionType", 167],
|
||||
["TSConstructorType", 168],
|
||||
["TSMappedType", 169],
|
||||
["TSTemplateLiteralType", 170],
|
||||
["TSAsExpression", 171],
|
||||
["TSSatisfiesExpression", 172],
|
||||
["TSTypeAssertion", 173],
|
||||
["TSImportEqualsDeclaration", 174],
|
||||
["TSExternalModuleReference", 175],
|
||||
["TSNonNullExpression", 176],
|
||||
["Decorator", 177],
|
||||
["TSExportAssignment", 178],
|
||||
["TSNamespaceExportDeclaration", 179],
|
||||
["TSInstantiationExpression", 180],
|
||||
["JSDocNullableType", 181],
|
||||
["JSDocNonNullableType", 182],
|
||||
["TSExternalModuleDeclaration", 159],
|
||||
["TSNamespaceDeclaration", 160],
|
||||
["TSGlobalDeclaration", 161],
|
||||
["TSModuleBlock", 162],
|
||||
["TSTypeLiteral", 163],
|
||||
["TSInferType", 164],
|
||||
["TSTypeQuery", 165],
|
||||
["TSImportType", 166],
|
||||
["TSImportTypeQualifiedName", 167],
|
||||
["TSFunctionType", 168],
|
||||
["TSConstructorType", 169],
|
||||
["TSMappedType", 170],
|
||||
["TSTemplateLiteralType", 171],
|
||||
["TSAsExpression", 172],
|
||||
["TSSatisfiesExpression", 173],
|
||||
["TSTypeAssertion", 174],
|
||||
["TSImportEqualsDeclaration", 175],
|
||||
["TSExternalModuleReference", 176],
|
||||
["TSNonNullExpression", 177],
|
||||
["Decorator", 178],
|
||||
["TSExportAssignment", 179],
|
||||
["TSNamespaceExportDeclaration", 180],
|
||||
["TSInstantiationExpression", 181],
|
||||
["JSDocNullableType", 182],
|
||||
["JSDocNonNullableType", 183],
|
||||
]);
|
||||
|
||||
export const NODE_TYPES_COUNT = 183;
|
||||
export const NODE_TYPES_COUNT = 184;
|
||||
export const LEAF_NODE_TYPES_COUNT = 40;
|
||||
@@ -160,7 +160,8 @@ import {
|
||||
TSIndexSignatureName,
|
||||
TSInterfaceHeritage,
|
||||
TSTypePredicate,
|
||||
TSModuleDeclaration,
|
||||
TSExternalModuleDeclaration,
|
||||
TSNamespaceDeclaration,
|
||||
TSGlobalDeclaration,
|
||||
TSModuleBlock,
|
||||
TSTypeLiteral,
|
||||
@@ -1512,12 +1513,15 @@ function walkStatement(pos, ast, visitors) {
|
||||
walkBoxTSEnumDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 38:
|
||||
walkBoxTSModuleDeclaration(pos + 8, ast, visitors);
|
||||
walkBoxTSExternalModuleDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 39:
|
||||
walkBoxTSGlobalDeclaration(pos + 8, ast, visitors);
|
||||
walkBoxTSNamespaceDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 40:
|
||||
walkBoxTSGlobalDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 41:
|
||||
walkBoxTSImportEqualsDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 64:
|
||||
@@ -1591,12 +1595,15 @@ function walkDeclaration(pos, ast, visitors) {
|
||||
walkBoxTSEnumDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 38:
|
||||
walkBoxTSModuleDeclaration(pos + 8, ast, visitors);
|
||||
walkBoxTSExternalModuleDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 39:
|
||||
walkBoxTSGlobalDeclaration(pos + 8, ast, visitors);
|
||||
walkBoxTSNamespaceDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 40:
|
||||
walkBoxTSGlobalDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 41:
|
||||
walkBoxTSImportEqualsDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
default:
|
||||
@@ -4433,51 +4440,55 @@ function walkTSTypePredicateName(pos, ast, visitors) {
|
||||
}
|
||||
}
|
||||
|
||||
function walkTSModuleDeclaration(pos, ast, visitors) {
|
||||
function walkTSExternalModuleDeclaration(pos, ast, visitors) {
|
||||
const enterExit = visitors[159];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
if (enterExit !== null) {
|
||||
({ enter, exit } = enterExit);
|
||||
node = new TSModuleDeclaration(pos, ast);
|
||||
node = new TSExternalModuleDeclaration(pos, ast);
|
||||
if (enter !== null) enter(node);
|
||||
}
|
||||
|
||||
walkTSModuleDeclarationName(pos + 16, ast, visitors);
|
||||
walkOptionTSModuleDeclarationBody(pos + 72, ast, visitors);
|
||||
walkStringLiteral(pos + 16, ast, visitors);
|
||||
walkOptionBoxTSModuleBlock(pos + 64, ast, visitors);
|
||||
|
||||
if (exit !== null) exit(node);
|
||||
}
|
||||
|
||||
function walkTSModuleDeclarationName(pos, ast, visitors) {
|
||||
switch (ast.buffer[pos]) {
|
||||
case 0:
|
||||
walkBindingIdentifier(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 1:
|
||||
walkStringLiteral(pos + 8, ast, visitors);
|
||||
return;
|
||||
default:
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleDeclarationName`);
|
||||
function walkTSNamespaceDeclaration(pos, ast, visitors) {
|
||||
const enterExit = visitors[160];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
if (enterExit !== null) {
|
||||
({ enter, exit } = enterExit);
|
||||
node = new TSNamespaceDeclaration(pos, ast);
|
||||
if (enter !== null) enter(node);
|
||||
}
|
||||
|
||||
walkBindingIdentifier(pos + 16, ast, visitors);
|
||||
walkTSNamespaceDeclarationBody(pos + 48, ast, visitors);
|
||||
|
||||
if (exit !== null) exit(node);
|
||||
}
|
||||
|
||||
function walkTSModuleDeclarationBody(pos, ast, visitors) {
|
||||
function walkTSNamespaceDeclarationBody(pos, ast, visitors) {
|
||||
switch (ast.buffer[pos]) {
|
||||
case 0:
|
||||
walkBoxTSModuleDeclaration(pos + 8, ast, visitors);
|
||||
walkBoxTSNamespaceDeclaration(pos + 8, ast, visitors);
|
||||
return;
|
||||
case 1:
|
||||
walkBoxTSModuleBlock(pos + 8, ast, visitors);
|
||||
return;
|
||||
default:
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSModuleDeclarationBody`);
|
||||
throw new Error(`Unexpected discriminant ${ast.buffer[pos]} for TSNamespaceDeclarationBody`);
|
||||
}
|
||||
}
|
||||
|
||||
function walkTSGlobalDeclaration(pos, ast, visitors) {
|
||||
const enterExit = visitors[160];
|
||||
const enterExit = visitors[161];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4493,7 +4504,7 @@ function walkTSGlobalDeclaration(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSModuleBlock(pos, ast, visitors) {
|
||||
const enterExit = visitors[161];
|
||||
const enterExit = visitors[162];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4509,7 +4520,7 @@ function walkTSModuleBlock(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSTypeLiteral(pos, ast, visitors) {
|
||||
const enterExit = visitors[162];
|
||||
const enterExit = visitors[163];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4525,7 +4536,7 @@ function walkTSTypeLiteral(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSInferType(pos, ast, visitors) {
|
||||
const enterExit = visitors[163];
|
||||
const enterExit = visitors[164];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4541,7 +4552,7 @@ function walkTSInferType(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSTypeQuery(pos, ast, visitors) {
|
||||
const enterExit = visitors[164];
|
||||
const enterExit = visitors[165];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4577,7 +4588,7 @@ function walkTSTypeQueryExprName(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSImportType(pos, ast, visitors) {
|
||||
const enterExit = visitors[165];
|
||||
const enterExit = visitors[166];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4609,7 +4620,7 @@ function walkTSImportTypeQualifier(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSImportTypeQualifiedName(pos, ast, visitors) {
|
||||
const enterExit = visitors[166];
|
||||
const enterExit = visitors[167];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4626,7 +4637,7 @@ function walkTSImportTypeQualifiedName(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSFunctionType(pos, ast, visitors) {
|
||||
const enterExit = visitors[167];
|
||||
const enterExit = visitors[168];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4644,7 +4655,7 @@ function walkTSFunctionType(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSConstructorType(pos, ast, visitors) {
|
||||
const enterExit = visitors[168];
|
||||
const enterExit = visitors[169];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4662,7 +4673,7 @@ function walkTSConstructorType(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSMappedType(pos, ast, visitors) {
|
||||
const enterExit = visitors[169];
|
||||
const enterExit = visitors[170];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4681,7 +4692,7 @@ function walkTSMappedType(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSTemplateLiteralType(pos, ast, visitors) {
|
||||
const enterExit = visitors[170];
|
||||
const enterExit = visitors[171];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4698,7 +4709,7 @@ function walkTSTemplateLiteralType(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSAsExpression(pos, ast, visitors) {
|
||||
const enterExit = visitors[171];
|
||||
const enterExit = visitors[172];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4715,7 +4726,7 @@ function walkTSAsExpression(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSSatisfiesExpression(pos, ast, visitors) {
|
||||
const enterExit = visitors[172];
|
||||
const enterExit = visitors[173];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4732,7 +4743,7 @@ function walkTSSatisfiesExpression(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSTypeAssertion(pos, ast, visitors) {
|
||||
const enterExit = visitors[173];
|
||||
const enterExit = visitors[174];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4749,7 +4760,7 @@ function walkTSTypeAssertion(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSImportEqualsDeclaration(pos, ast, visitors) {
|
||||
const enterExit = visitors[174];
|
||||
const enterExit = visitors[175];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4782,7 +4793,7 @@ function walkTSModuleReference(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSExternalModuleReference(pos, ast, visitors) {
|
||||
const enterExit = visitors[175];
|
||||
const enterExit = visitors[176];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4798,7 +4809,7 @@ function walkTSExternalModuleReference(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSNonNullExpression(pos, ast, visitors) {
|
||||
const enterExit = visitors[176];
|
||||
const enterExit = visitors[177];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4814,7 +4825,7 @@ function walkTSNonNullExpression(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkDecorator(pos, ast, visitors) {
|
||||
const enterExit = visitors[177];
|
||||
const enterExit = visitors[178];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4830,7 +4841,7 @@ function walkDecorator(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSExportAssignment(pos, ast, visitors) {
|
||||
const enterExit = visitors[178];
|
||||
const enterExit = visitors[179];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4846,7 +4857,7 @@ function walkTSExportAssignment(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSNamespaceExportDeclaration(pos, ast, visitors) {
|
||||
const enterExit = visitors[179];
|
||||
const enterExit = visitors[180];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4862,7 +4873,7 @@ function walkTSNamespaceExportDeclaration(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkTSInstantiationExpression(pos, ast, visitors) {
|
||||
const enterExit = visitors[180];
|
||||
const enterExit = visitors[181];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4879,7 +4890,7 @@ function walkTSInstantiationExpression(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkJSDocNullableType(pos, ast, visitors) {
|
||||
const enterExit = visitors[181];
|
||||
const enterExit = visitors[182];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -4895,7 +4906,7 @@ function walkJSDocNullableType(pos, ast, visitors) {
|
||||
}
|
||||
|
||||
function walkJSDocNonNullableType(pos, ast, visitors) {
|
||||
const enterExit = visitors[182];
|
||||
const enterExit = visitors[183];
|
||||
let node,
|
||||
enter,
|
||||
exit = null;
|
||||
@@ -5329,8 +5340,12 @@ function walkBoxTSEnumDeclaration(pos, ast, visitors) {
|
||||
return walkTSEnumDeclaration(ast.buffer.int32[pos >> 2], ast, visitors);
|
||||
}
|
||||
|
||||
function walkBoxTSModuleDeclaration(pos, ast, visitors) {
|
||||
return walkTSModuleDeclaration(ast.buffer.int32[pos >> 2], ast, visitors);
|
||||
function walkBoxTSExternalModuleDeclaration(pos, ast, visitors) {
|
||||
return walkTSExternalModuleDeclaration(ast.buffer.int32[pos >> 2], ast, visitors);
|
||||
}
|
||||
|
||||
function walkBoxTSNamespaceDeclaration(pos, ast, visitors) {
|
||||
return walkTSNamespaceDeclaration(ast.buffer.int32[pos >> 2], ast, visitors);
|
||||
}
|
||||
|
||||
function walkBoxTSGlobalDeclaration(pos, ast, visitors) {
|
||||
@@ -5969,14 +5984,15 @@ function walkBoxTSMethodSignature(pos, ast, visitors) {
|
||||
return walkTSMethodSignature(ast.buffer.int32[pos >> 2], ast, visitors);
|
||||
}
|
||||
|
||||
function walkOptionTSModuleDeclarationBody(pos, ast, visitors) {
|
||||
if (!(ast.buffer[pos] === 2)) walkTSModuleDeclarationBody(pos, ast, visitors);
|
||||
}
|
||||
|
||||
function walkBoxTSModuleBlock(pos, ast, visitors) {
|
||||
return walkTSModuleBlock(ast.buffer.int32[pos >> 2], ast, visitors);
|
||||
}
|
||||
|
||||
function walkOptionBoxTSModuleBlock(pos, ast, visitors) {
|
||||
if (!(ast.buffer.int32[pos >> 2] === 0 && ast.buffer.int32[(pos >> 2) + 1] === 0))
|
||||
walkBoxTSModuleBlock(pos, ast, visitors);
|
||||
}
|
||||
|
||||
function walkBoxTSTypeParameter(pos, ast, visitors) {
|
||||
return walkTSTypeParameter(ast.buffer.int32[pos >> 2], ast, visitors);
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1477,6 +1477,8 @@ export interface TSTypePredicate extends Span {
|
||||
|
||||
export type TSTypePredicateName = IdentifierName | TSThisType;
|
||||
|
||||
export type TSModuleDeclarationKind = "module" | "namespace";
|
||||
|
||||
export interface TSModuleDeclaration extends Span {
|
||||
type: "TSModuleDeclaration";
|
||||
id: BindingIdentifier | StringLiteral | TSQualifiedName;
|
||||
@@ -1487,8 +1489,6 @@ export interface TSModuleDeclaration extends Span {
|
||||
parent?: Node;
|
||||
}
|
||||
|
||||
export type TSModuleDeclarationKind = "module" | "namespace";
|
||||
|
||||
export interface TSGlobalDeclaration extends Span {
|
||||
type: "TSModuleDeclaration";
|
||||
id: IdentifierName;
|
||||
|
||||
@@ -309,7 +309,8 @@ fn generate_scope_code(struct_def: &StructDef) -> (TokenStream, TokenStream, boo
|
||||
| "Function"
|
||||
| "ArrowFunctionExpression"
|
||||
| "StaticBlock"
|
||||
| "TSModuleDeclaration"
|
||||
| "TSExternalModuleDeclaration"
|
||||
| "TSNamespaceDeclaration"
|
||||
| "TSGlobalDeclaration"
|
||||
);
|
||||
if is_block_scope {
|
||||
|
||||
Loaded 100 of 103 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user