diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index da4904ff996..d1c4de29059 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1489,7 +1489,7 @@ namespace ts { } const declaration = symbol.valueDeclaration; const e = getDeclaredJavascriptInitializer(declaration) || getAssignedJavascriptInitializer(declaration); - return e ? e.symbol : symbol; + return e && e.symbol ? e.symbol : symbol; } /** Get the declaration initializer, when the initializer is container-like (See getJavascriptInitializer) */ diff --git a/tests/baselines/reference/jsContainerMergeTsDeclaration.errors.txt b/tests/baselines/reference/jsContainerMergeTsDeclaration.errors.txt new file mode 100644 index 00000000000..d5e6c331e77 --- /dev/null +++ b/tests/baselines/reference/jsContainerMergeTsDeclaration.errors.txt @@ -0,0 +1,22 @@ +error TS5055: Cannot write file 'tests/cases/conformance/salsa/a.js' because it would overwrite input file. + Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. +tests/cases/conformance/salsa/a.js(1,23): error TS2300: Duplicate identifier 'x'. +tests/cases/conformance/salsa/b.ts(1,5): error TS2300: Duplicate identifier 'x'. + + +!!! error TS5055: Cannot write file 'tests/cases/conformance/salsa/a.js' because it would overwrite input file. +!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. +==== tests/cases/conformance/salsa/a.js (1 errors) ==== + var /*1*/x = function foo() { + ~~~ +!!! error TS2300: Duplicate identifier 'x'. + } + x.a = function bar() { + } +==== tests/cases/conformance/salsa/b.ts (1 errors) ==== + var x = function () { + ~ +!!! error TS2300: Duplicate identifier 'x'. + return 1; + }(); + \ No newline at end of file diff --git a/tests/baselines/reference/jsContainerMergeTsDeclaration.js b/tests/baselines/reference/jsContainerMergeTsDeclaration.js new file mode 100644 index 00000000000..9e81ff2e536 --- /dev/null +++ b/tests/baselines/reference/jsContainerMergeTsDeclaration.js @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/salsa/jsContainerMergeTsDeclaration.ts] //// + +//// [a.js] +var /*1*/x = function foo() { +} +x.a = function bar() { +} +//// [b.ts] +var x = function () { + return 1; +}(); + + +//// [b.js] +var x = function () { + return 1; +}(); diff --git a/tests/baselines/reference/jsContainerMergeTsDeclaration.symbols b/tests/baselines/reference/jsContainerMergeTsDeclaration.symbols new file mode 100644 index 00000000000..080cf745cba --- /dev/null +++ b/tests/baselines/reference/jsContainerMergeTsDeclaration.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/salsa/a.js === +var /*1*/x = function foo() { +>x : Symbol(x, Decl(a.js, 0, 3), Decl(a.js, 1, 1), Decl(b.ts, 0, 3)) +>foo : Symbol(foo, Decl(a.js, 0, 12)) +} +x.a = function bar() { +>x.a : Symbol(foo.a, Decl(a.js, 1, 1)) +>x : Symbol(x, Decl(a.js, 0, 3), Decl(a.js, 1, 1), Decl(b.ts, 0, 3)) +>a : Symbol(foo.a, Decl(a.js, 1, 1)) +>bar : Symbol(bar, Decl(a.js, 2, 5)) +} +=== tests/cases/conformance/salsa/b.ts === +var x = function () { +>x : Symbol(x, Decl(a.js, 0, 3), Decl(a.js, 1, 1), Decl(b.ts, 0, 3)) + + return 1; +}(); + diff --git a/tests/baselines/reference/jsContainerMergeTsDeclaration.types b/tests/baselines/reference/jsContainerMergeTsDeclaration.types new file mode 100644 index 00000000000..7d563176998 --- /dev/null +++ b/tests/baselines/reference/jsContainerMergeTsDeclaration.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/salsa/a.js === +var /*1*/x = function foo() { +>x : { (): void; a: () => void; } +>function foo() {} : { (): void; a: () => void; } +>foo : { (): void; a: () => void; } +} +x.a = function bar() { +>x.a = function bar() {} : () => void +>x.a : () => void +>x : { (): void; a: () => void; } +>a : () => void +>function bar() {} : () => void +>bar : () => void +} +=== tests/cases/conformance/salsa/b.ts === +var x = function () { +>x : { (): void; a: () => void; } +>function () { return 1;}() : number +>function () { return 1;} : () => number + + return 1; +>1 : 1 + +}(); + diff --git a/tests/cases/conformance/salsa/jsContainerMergeTsDeclaration.ts b/tests/cases/conformance/salsa/jsContainerMergeTsDeclaration.ts new file mode 100644 index 00000000000..5a5ba7f49d5 --- /dev/null +++ b/tests/cases/conformance/salsa/jsContainerMergeTsDeclaration.ts @@ -0,0 +1,11 @@ +// @allowJs: true +// @checkJs: true +// @Filename: a.js +var /*1*/x = function foo() { +} +x.a = function bar() { +} +// @Filename: b.ts +var x = function () { + return 1; +}();