Skip to content

Commit 235356e

Browse files
authored
Handle synthetic nodes correctly as namespace identifiers in system transform (microsoft#19623)
* Handle synthetic nodes correctly as namespace identifiers in system transform * Add ref to issue in comment * Lock newline for ci
1 parent e9841f3 commit 235356e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/compiler/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4319,7 +4319,7 @@ namespace ts {
43194319
const namespaceDeclaration = getNamespaceDeclarationNode(node);
43204320
if (namespaceDeclaration && !isDefaultImport(node)) {
43214321
const name = namespaceDeclaration.name;
4322-
return isGeneratedIdentifier(name) ? name : createIdentifier(getSourceTextOfNodeFromSourceFile(sourceFile, namespaceDeclaration.name));
4322+
return isGeneratedIdentifier(name) ? name : createIdentifier(getSourceTextOfNodeFromSourceFile(sourceFile, name) || idText(name));
43234323
}
43244324
if (node.kind === SyntaxKind.ImportDeclaration && (<ImportDeclaration>node).importClause) {
43254325
return getGeneratedNameForNode(node);

src/harness/unittests/transform.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,38 @@ namespace ts {
192192
};
193193
}
194194
});
195+
196+
// https://github.com/Microsoft/TypeScript/issues/19618
197+
testBaseline("transformAddImportStar", () => {
198+
return ts.transpileModule("", {
199+
transformers: {
200+
before: [transformAddImportStar],
201+
},
202+
compilerOptions: {
203+
target: ts.ScriptTarget.ES5,
204+
module: ts.ModuleKind.System,
205+
newLine: NewLineKind.CarriageReturnLineFeed,
206+
}
207+
}).outputText;
208+
209+
function transformAddImportStar(_context: ts.TransformationContext) {
210+
return (sourceFile: ts.SourceFile): ts.SourceFile => {
211+
return visitNode(sourceFile);
212+
};
213+
function visitNode(sf: ts.SourceFile) {
214+
// produce `import * as i0 from './comp';
215+
const importStar = ts.createImportDeclaration(
216+
/*decorators*/ undefined,
217+
/*modifiers*/ undefined,
218+
/*importClause*/ ts.createImportClause(
219+
/*name*/ undefined,
220+
ts.createNamespaceImport(ts.createIdentifier("i0"))
221+
),
222+
/*moduleSpecifier*/ ts.createLiteral("./comp1"));
223+
return ts.updateSourceFileNode(sf, [importStar]);
224+
}
225+
}
226+
});
195227
});
196228
}
197229

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
System.register(["./comp1"], function (exports_1, context_1) {
2+
var __moduleName = context_1 && context_1.id;
3+
var i0;
4+
return {
5+
setters: [
6+
function (i0_1) {
7+
i0 = i0_1;
8+
}
9+
],
10+
execute: function () {
11+
}
12+
};
13+
});

0 commit comments

Comments
 (0)