-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): parse import attributes in TSImportType (#2436)
close: #2394 https://github.com/microsoft/TypeScript/blob/64d2eeea7b9c7f1a79edf42cb99f302535136a2e/src/compiler/types.ts#L2177-L2185 The corresponding test cases were skipped, so I manually added some cases to misc https://github.com/oxc-project/oxc/blob/f5db48237ff774d778bdb48e13950b5a8876f361/tasks/coverage/src/typescript.rs#L118-L121
- Loading branch information
Showing
9 changed files
with
157 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
codegen_misc Summary: | ||
AST Parsed : 10/10 (100.00%) | ||
Positive Passed: 10/10 (100.00%) | ||
AST Parsed : 11/11 (100.00%) | ||
Positive Passed: 11/11 (100.00%) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// copy from https://github.com/microsoft/TypeScript/blob/main/tests/cases/conformance/node/nodeModulesImportAttributesTypeModeDeclarationEmitErrors.ts#L72 | ||
|
||
// @filename: /node_modules/pkg/import.d.ts | ||
export interface ImportInterface {} | ||
|
||
// @filename: /node_modules/pkg/require.d.ts | ||
export interface RequireInterface {} | ||
|
||
// @filename: /index.ts | ||
export type LocalInterface = | ||
& import("pkg", { with: {"resolution-mode": "foobar"} }).RequireInterface | ||
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface; | ||
|
||
export const a = (null as any as import("pkg", { with: {"resolution-mode": "foobar"} }).RequireInterface); | ||
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface); | ||
|
||
// @filename: /other.ts | ||
// missing with: | ||
export type LocalInterface = | ||
& import("pkg", {"resolution-mode": "require"}).RequireInterface | ||
& import("pkg", {"resolution-mode": "import"}).ImportInterface; | ||
|
||
export const a = (null as any as import("pkg", {"resolution-mode": "require"}).RequireInterface); | ||
export const b = (null as any as import("pkg", {"resolution-mode": "import"}).ImportInterface); | ||
|
||
// @filename: /other2.ts | ||
// wrong attribute key | ||
export type LocalInterface = | ||
& import("pkg", { with: {"bad": "require"} }).RequireInterface | ||
& import("pkg", { with: {"bad": "import"} }).ImportInterface; | ||
|
||
export const a = (null as any as import("pkg", { with: {"bad": "require"} }).RequireInterface); | ||
export const b = (null as any as import("pkg", { with: {"bad": "import"} }).ImportInterface); | ||
|
||
// @filename: /other3.ts | ||
// Array instead of object-y thing | ||
export type LocalInterface = | ||
& import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface | ||
& import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; | ||
|
||
export const a = (null as any as import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface); | ||
export const b = (null as any as import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface); | ||
|
||
// @filename: /other4.ts | ||
// Indirected attribute objecty-thing - not allowed | ||
type Attribute1 = { with: {"resolution-mode": "require"} }; | ||
type Attribute2 = { with: {"resolution-mode": "import"} }; | ||
|
||
export type LocalInterface = | ||
& import("pkg", Attribute1).RequireInterface | ||
& import("pkg", Attribute2).ImportInterface; | ||
|
||
export const a = (null as any as import("pkg", Attribute1).RequireInterface); | ||
export const b = (null as any as import("pkg", Attribute2).ImportInterface); | ||
|
||
// @filename: /other5.ts | ||
export type LocalInterface = | ||
& import("pkg", { with: {} }).RequireInterface | ||
& import("pkg", { with: {} }).ImportInterface; | ||
|
||
export const a = (null as any as import("pkg", { with: {} }).RequireInterface); | ||
export const b = (null as any as import("pkg", { with: {} }).ImportInterface); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type A = import("foo", {with: {type: "json"}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
prettier_misc Summary: | ||
AST Parsed : 10/10 (100.00%) | ||
Positive Passed: 6/10 (60.00%) | ||
AST Parsed : 11/11 (100.00%) | ||
Positive Passed: 6/11 (54.55%) | ||
Expect to Parse: "pass/oxc-1740.tsx" | ||
Expect to Parse: "pass/oxc-2087.ts" | ||
Expect to Parse: "pass/oxc-2394.ts" | ||
Expect to Parse: "pass/swc-1627.js" | ||
Expect to Parse: "pass/swc-8243.tsx" |