feat(53656): Add support for the updated import attributes proposal (#54242)

This commit is contained in:
Oleksandr T
2023-09-26 23:20:15 +03:00
committed by GitHub
parent b12af0fa2b
commit 2e9e9a292c
169 changed files with 32223 additions and 374 deletions
+2 -2
View File
@@ -309,7 +309,7 @@ describe("unittests:: TransformAPI", () => {
const exports = [{ name: "x" }];
const exportSpecifiers = exports.map(e => ts.factory.createExportSpecifier(/*isTypeOnly*/ false, e.name, e.name));
const exportClause = ts.factory.createNamedExports(exportSpecifiers);
const newEd = ts.factory.updateExportDeclaration(ed, ed.modifiers, ed.isTypeOnly, exportClause, ed.moduleSpecifier, ed.assertClause);
const newEd = ts.factory.updateExportDeclaration(ed, ed.modifiers, ed.isTypeOnly, exportClause, ed.moduleSpecifier, ed.attributes);
return newEd as ts.Node as T;
}
@@ -347,7 +347,7 @@ describe("unittests:: TransformAPI", () => {
ts.factory.createNamespaceImport(ts.factory.createIdentifier("i0")),
),
/*moduleSpecifier*/ ts.factory.createStringLiteral("./comp1"),
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
return ts.factory.updateSourceFile(sf, [importStar]);
}
@@ -376,6 +376,77 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
],
});
verifyTscWatch({
scenario: "moduleResolution",
subScenario: "module resolutions from files with partially used import attributes",
sys: () =>
createWatchedSystem([
{
path: `/user/username/projects/myproject/tsconfig.json`,
content: JSON.stringify({
compilerOptions: { moduleResolution: "node16" },
}),
},
{
path: `/user/username/projects/myproject/index.ts`,
content: Utils.dedent`
import type { ImportInterface } from "pkg" with { "resolution-mode": "import" };
import type { RequireInterface } from "pkg1" with { "resolution-mode": "require" };
import {x} from "./a";
`,
},
{
path: `/user/username/projects/myproject/a.ts`,
content: Utils.dedent`
export const x = 10;
`,
},
{
path: `/user/username/projects/myproject/node_modules/pkg/package.json`,
content: JSON.stringify({
name: "pkg",
version: "0.0.1",
exports: {
import: "./import.js",
require: "./require.js",
},
}),
},
{
path: `/user/username/projects/myproject/node_modules/pkg/import.d.ts`,
content: `export interface ImportInterface {}`,
},
{
path: `/user/username/projects/myproject/node_modules/pkg/require.d.ts`,
content: `export interface RequireInterface {}`,
},
{
path: `/user/username/projects/myproject/node_modules/pkg1/package.json`,
content: JSON.stringify({
name: "pkg1",
version: "0.0.1",
exports: {
import: "./import.js",
require: "./require.js",
},
}),
},
{
path: `/user/username/projects/myproject/node_modules/pkg1/import.d.ts`,
content: `export interface ImportInterface {}`,
},
libFile,
], { currentDirectory: "/user/username/projects/myproject" }),
commandLineArgs: ["-w", "--traceResolution"],
edits: [
{
caption: "modify aFile by adding import",
edit: sys => sys.appendFile(`/user/username/projects/myproject/a.ts`, `import type { ImportInterface } from "pkg" with { "resolution-mode": "import" }`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
],
});
verifyTscWatch({
scenario: "moduleResolution",
subScenario: "type reference resolutions reuse",