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
5 changes: 0 additions & 5 deletions crates/oxc_parser/src/lexer/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,6 @@ impl Kind {
self.is_literal_property_name() || self == Self::PrivateIdentifier
}

#[inline]
pub fn is_variable_declaration(self) -> bool {
matches!(self, Var | Let | Const)
}

#[rustfmt::skip]
#[inline]
pub fn is_assignment_operator(self) -> bool {
Expand Down
34 changes: 17 additions & 17 deletions crates/oxc_parser/src/ts/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,16 @@ impl<'a> ParserImpl<'a> {
}
}
match kind {
Kind::Global | Kind::Module | Kind::Namespace => {
let decl = self.parse_ts_module_declaration(start_span, modifiers);
Declaration::TSModuleDeclaration(decl)
}
Kind::Type => self.parse_ts_type_alias_declaration(start_span, modifiers),
Kind::Enum => self.parse_ts_enum_declaration(start_span, modifiers),
Kind::Interface => {
Kind::Var | Kind::Let | Kind::Const => {
let kind = self.get_variable_declaration_kind();
self.bump_any();
self.parse_ts_interface_declaration(start_span, modifiers)
let decl = self.parse_variable_declaration(
start_span,
kind,
VariableDeclarationParent::Statement,
modifiers,
);
Declaration::VariableDeclaration(decl)
}
Kind::Class => {
let decl = self.parse_class_declaration(start_span, modifiers, decorators);
Expand All @@ -451,16 +452,15 @@ impl<'a> ParserImpl<'a> {
}
self.parse_ts_import_equals_declaration(import_kind, identifier, start_span)
}
kind if kind.is_variable_declaration() => {
let kind = self.get_variable_declaration_kind();
Kind::Global | Kind::Module | Kind::Namespace if self.is_ts => {
let decl = self.parse_ts_module_declaration(start_span, modifiers);
Declaration::TSModuleDeclaration(decl)
}
Kind::Type if self.is_ts => self.parse_ts_type_alias_declaration(start_span, modifiers),
Kind::Enum if self.is_ts => self.parse_ts_enum_declaration(start_span, modifiers),
Kind::Interface if self.is_ts => {
self.bump_any();
let decl = self.parse_variable_declaration(
start_span,
kind,
VariableDeclarationParent::Statement,
modifiers,
);
Declaration::VariableDeclaration(decl)
self.parse_ts_interface_declaration(start_span, modifiers)
}
_ if self.at_function_with_async() => {
let declare = modifiers.contains(ModifierKind::Declare);
Expand Down
22 changes: 15 additions & 7 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: 98d18aa4
parser_babel Summary:
AST Parsed : 2403/2419 (99.34%)
Positive Passed: 2381/2419 (98.43%)
Negative Passed: 1640/1756 (93.39%)
Negative Passed: 1642/1756 (93.51%)
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/invalid-startindex-and-startline-specified-without-startcolumn/input.js

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/categorized/startline-and-startcolumn-specified/input.js
Expand Down Expand Up @@ -70,10 +70,6 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/class-private-property/typescript-invalid-abstract-babel-7/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/flow/expect-plugin/export-interface/input.js

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/flow/expect-plugin/export-type/input.js

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/arrow-function/arrow-like-in-conditional-2/input.ts

Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/cast/satisfies-const-error/input.ts
Expand Down Expand Up @@ -12077,10 +12073,22 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/flow/expect-plugin/export-type-named/input.js:2:13]
╭─[babel/packages/babel-parser/test/fixtures/flow/expect-plugin/export-interface/input.js:1:8]
1 │ export interface Foo {}
· ─────────
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/flow/expect-plugin/export-type/input.js:1:8]
1 │ export type Foo = number;
· ────
╰────

× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/flow/expect-plugin/export-type-named/input.js:2:8]
1 │ var Foo;
2 │ export type { Foo };
·
· ───
╰────

× Unexpected token
Expand Down
57 changes: 21 additions & 36 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8927,19 +8927,12 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────
help: Try insert a semicolon here

× Duplicated export 'foo'
╭─[typescript/tests/cases/compiler/jsdocTypedefNoCrash2.ts:1:13]
× Unexpected token
╭─[typescript/tests/cases/compiler/jsdocTypedefNoCrash2.ts:1:8]
1 │ export type foo = 5;
· ─┬─
· ╰── Export has already been declared here
· ────
2 │ /**
╰────
╭─[typescript/tests/cases/compiler/jsdocTypedefNoCrash2.ts:6:14]
5 │ */
6 │ export const foo = 5;
· ─┬─
· ╰── It cannot be redeclared here
╰────

× Unexpected token
╭─[typescript/tests/cases/compiler/jsxAttributeMissingInitializer.tsx:1:21]
Expand Down Expand Up @@ -20723,9 +20716,9 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────

× Unexpected token
╭─[typescript/tests/cases/conformance/externalModules/typeOnly/exportNamespace_js.ts:1:13]
╭─[typescript/tests/cases/conformance/externalModules/typeOnly/exportNamespace_js.ts:1:8]
1 │ export type * from './a';
·
· ───
╰────

× TS(2207): The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.
Expand Down Expand Up @@ -21204,12 +21197,12 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────

× Unexpected token
╭─[typescript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsEnums.ts:10:1]
9
10 │ enum C {}
· ────
11
╰────
╭─[typescript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsEnums.ts:4:8]
3
4export enum A {}
· ────
5
╰────

× TS(8002): 'import ... =' can only be used in TypeScript files.
╭─[typescript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportFormsErr.ts:1:1]
Expand All @@ -21226,27 +21219,19 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
╰────

× Unexpected token
╭─[typescript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsInterfaces.ts:7:8]
6export interface B {
7 cat: string;
· ─
8}
╭─[typescript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsInterfaces.ts:4:8]
3
4export interface A {}
· ─────────
5
╰────

× 'export statement' declaration can only be used at the top level of a module
╭─[typescript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReferences4.ts:10:9]
9 │ // @ts-ignore
10 │ export { thing };
· ──────
11 │ }
╰────

× 'export statement' declaration can only be used at the top level of a module
╭─[typescript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReferences4.ts:6:5]
× Unexpected token
╭─[typescript/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReferences4.ts:4:8]
3 │ // @ts-ignore
4 │ export namespace A {
· ─────────
5 │ // @ts-ignore
6 │ export namespace B {
· ──────
7 │ const Something = require("fs").Something;
╰────

× Identifier `err` has already been declared
Expand Down
Loading