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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2389,7 +2389,7 @@ pub struct ImportExpression<'a> {
pub span: Span,
pub source: Expression<'a>,
pub options: Option<Expression<'a>>,
#[estree(skip)]
#[js_only]
pub phase: Option<ImportPhase>,
}

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,7 @@ impl ESTree for ImportExpression<'_> {
state.serialize_field("end", &self.span.end);
state.serialize_field("source", &self.source);
state.serialize_field("options", &self.options);
state.serialize_js_field("phase", &self.phase);
state.end();
}
}
Expand Down
3 changes: 1 addition & 2 deletions napi/parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ If you need all ASTs in the same with-TS-properties format, use the `astType: 't
The only differences between Oxc's AST and ESTree / TS-ESTree are:

- Support for Stage 3 ECMA features [`import defer`](https://github.com/tc39/proposal-defer-import-eval)
and [`import source`](https://github.com/tc39/proposal-source-phase-imports) on `ImportDeclaration`
(not supported on `ImportExpression` yet).
and [`import source`](https://github.com/tc39/proposal-source-phase-imports).
- Addition of a non-standard `hashbang` field to `Program`.

That aside, the AST should completely align with Acorn's ESTree AST or TS-ESLint's TS-ESTree.
Expand Down
1 change: 1 addition & 0 deletions napi/parser/generated/deserialize/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ function deserializeImportExpression(pos) {
end: deserializeU32(pos + 4),
source: deserializeExpression(pos + 8),
options: deserializeOptionExpression(pos + 24),
phase: deserializeOptionImportPhase(pos + 40),
};
}

Expand Down
2 changes: 2 additions & 0 deletions napi/parser/test/parse-raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ describe('edge cases', () => {
// ECMA stage 3
'import defer * as ns from "x";',
'import source src from "x";',
'import.defer("x");',
'import.source("x");',
// `StringLiteral`s containing lone surrogates and/or lossy replacement characters
';"\\uD800\\uDBFF";',
';"�\\u{FFFD}";',
Expand Down
56 changes: 56 additions & 0 deletions napi/parser/test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,62 @@ describe('parse', () => {
});
});
});

describe('`ImportExpression`', () => {
describe('import.defer()', () => {
it('ESTree', () => {
const ret = parseSync('test.js', 'import.defer("x");');
expect(ret.errors.length).toBe(0);
expect(ret.program.body.length).toBe(1);
// @ts-ignore
expect(ret.program.body[0].expression).toEqual({
type: 'ImportExpression',
start: 0,
end: 17,
source: { type: 'Literal', start: 13, end: 16, value: 'x', raw: '"x"' },
options: null,
phase: 'defer',
});
});

it.skip('TS-ESTree', () => {
const ret = parseSync('test.ts', 'import.defer("x");');
expect(ret.errors.length).toBe(0);
expect(ret.program.body.length).toBe(1);
// @ts-ignore
expect(ret.program.body[0].expression).toEqual({
// TODO
});
});
});

describe('import.source()', () => {
it('ESTree', () => {
const ret = parseSync('test.js', 'import.source("x");');
expect(ret.errors.length).toBe(0);
expect(ret.program.body.length).toBe(1);
// @ts-ignore
expect(ret.program.body[0].expression).toEqual({
type: 'ImportExpression',
start: 0,
end: 18,
source: { type: 'Literal', start: 14, end: 17, value: 'x', raw: '"x"' },
options: null,
phase: 'source',
});
});

it.skip('TS-ESTree', () => {
const ret = parseSync('test.ts', 'import.source("x");');
expect(ret.errors.length).toBe(0);
expect(ret.program.body.length).toBe(1);
// @ts-ignore
expect(ret.program.body[0].expression).toEqual({
// TODO
});
});
});
});
});

it('lossy replacement character', () => {
Expand Down
1 change: 1 addition & 0 deletions npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ export interface ImportExpression extends Span {
type: 'ImportExpression';
source: Expression;
options: Expression | null;
phase?: ImportPhase | null;
}

export interface ImportDeclaration extends Span {
Expand Down
970 changes: 1 addition & 969 deletions tasks/coverage/snapshots/estree_test262.snap

Large diffs are not rendered by default.

Loading