Skip to content

Commit ff9bfc2

Browse files
committed
fix(parser): reject import something 'source'
1 parent 9f54a36 commit ff9bfc2

File tree

8 files changed

+48
-3
lines changed

8 files changed

+48
-3
lines changed

crates/oxc_parser/src/js/module.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ impl<'a> ParserImpl<'a> {
178178
None => unreachable!(),
179179
}
180180
} else {
181+
if has_default_specifier {
182+
// `import something 'source'`
183+
self.expect_without_advance(Kind::From);
184+
}
181185
None
182186
}
183187
} else {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import defer 'module';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import from 'module';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import source 'module';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import type 'module';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import unknown 'module';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import from from 'module';

tasks/coverage/snapshots/parser_misc.snap

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parser_misc Summary:
2-
AST Parsed : 49/49 (100.00%)
3-
Positive Passed: 49/49 (100.00%)
4-
Negative Passed: 113/113 (100.00%)
2+
AST Parsed : 50/50 (100.00%)
3+
Positive Passed: 50/50 (100.00%)
4+
Negative Passed: 118/118 (100.00%)
55

66
× Cannot assign to 'arguments' in strict mode
77
╭─[misc/fail/arguments-eval.ts:1:10]
@@ -187,13 +187,48 @@ Negative Passed: 113/113 (100.00%)
187187
· ╰── `,` or `]` expected
188188
╰────
189189
190+
× Expected `from` but found `string`
191+
╭─[misc/fail/import-defer-without-from.js:1:14]
192+
1import defer 'module';
193+
· ────┬───
194+
· ╰── `from` expected
195+
╰────
196+
197+
× Expected `from` but found `string`
198+
╭─[misc/fail/import-from-str.js:1:13]
199+
1import from 'module';
200+
· ────┬───
201+
· ╰── `from` expected
202+
╰────
203+
190204
× Expected `from` but found `Identifier`
191205
╭─[misc/fail/import-source-non-from.js:1:19]
192206
1import source foo bar from 'module';
193207
· ─┬─
194208
· ╰── `from` expected
195209
╰────
196210
211+
× Expected `from` but found `string`
212+
╭─[misc/fail/import-source-without-from.js:1:15]
213+
1import source 'module';
214+
· ────┬───
215+
· ╰── `from` expected
216+
╰────
217+
218+
× Expected `from` but found `string`
219+
╭─[misc/fail/import-type-without-from.ts:1:13]
220+
1import type 'module';
221+
· ────┬───
222+
· ╰── `from` expected
223+
╰────
224+
225+
× Expected `from` but found `string`
226+
╭─[misc/fail/import-without-from.js:1:16]
227+
1import unknown 'module';
228+
· ────┬───
229+
· ╰── `from` expected
230+
╰────
231+
197232
× Unexpected JSX expression
198233
╭─[misc/fail/jsx-in-js.js:1:20]
199234
1export const foo = <Foo />;

0 commit comments

Comments
 (0)