mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
Disallow JS/non-JS merge without crashing
Note that the error location is misleading because it's reported inside the merge step for the js initializer.
This commit is contained in:
parent
239f214b1c
commit
04ceb3d9bd
@ -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) */
|
||||
|
||||
@ -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;
|
||||
}();
|
||||
|
||||
17
tests/baselines/reference/jsContainerMergeTsDeclaration.js
Normal file
17
tests/baselines/reference/jsContainerMergeTsDeclaration.js
Normal file
@ -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;
|
||||
}();
|
||||
@ -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;
|
||||
}();
|
||||
|
||||
@ -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
|
||||
|
||||
}();
|
||||
|
||||
@ -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;
|
||||
}();
|
||||
Loading…
x
Reference in New Issue
Block a user