mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #6194 from Microsoft/fix4867_transpiling
Fix incorrectly emitting underscore of imported property
This commit is contained in:
commit
265069e296
@ -3889,7 +3889,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
// We create a synthetic copy of the identifier in order to avoid the rewriting that might
|
||||
// otherwise occur when the identifier is emitted.
|
||||
index = <Identifier | LiteralExpression>createSynthesizedNode(propName.kind);
|
||||
(<Identifier | LiteralExpression>index).text = (<Identifier | LiteralExpression>propName).text;
|
||||
// We need to unescape identifier here because when parsing an identifier prefixing with "__"
|
||||
// the parser need to append "_" in order to escape colliding with magic identifiers such as "__proto__"
|
||||
// Therefore, in order to correctly emit identifiers that are written in original TypeScript file,
|
||||
// we will unescapeIdentifier to remove additional underscore (if no underscore is added, the function will return original input string)
|
||||
(<Identifier | LiteralExpression>index).text = unescapeIdentifier((<Identifier | LiteralExpression>propName).text);
|
||||
}
|
||||
|
||||
return !nameIsComputed && index.kind === SyntaxKind.Identifier
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
tests/cases/conformance/es6/modules/m1.ts(6,5): error TS1005: ',' expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/modules/m1.ts (1 errors) ====
|
||||
|
||||
var R: any
|
||||
export default R = {
|
||||
"__": 20,
|
||||
"_": 10
|
||||
"___": 30
|
||||
~~~~~
|
||||
!!! error TS1005: ',' expected.
|
||||
}
|
||||
|
||||
==== tests/cases/conformance/es6/modules/m2.ts (0 errors) ====
|
||||
import R from "./m1";
|
||||
const { __, _, ___ } = R;
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
//// [tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores1.ts] ////
|
||||
|
||||
//// [m1.ts]
|
||||
|
||||
var R: any
|
||||
export default R = {
|
||||
"__": 20,
|
||||
"_": 10
|
||||
"___": 30
|
||||
}
|
||||
|
||||
//// [m2.ts]
|
||||
import R from "./m1";
|
||||
const { __, _, ___ } = R;
|
||||
|
||||
|
||||
//// [m1.js]
|
||||
"use strict";
|
||||
var R;
|
||||
exports.__esModule = true;
|
||||
exports["default"] = R = {
|
||||
"__": 20,
|
||||
"_": 10,
|
||||
"___": 30
|
||||
};
|
||||
//// [m2.js]
|
||||
"use strict";
|
||||
var m1_1 = require("./m1");
|
||||
var __ = m1_1["default"].__, _ = m1_1["default"]._, ___ = m1_1["default"].___;
|
||||
@ -0,0 +1,27 @@
|
||||
//// [tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores2.ts] ////
|
||||
|
||||
//// [m1.ts]
|
||||
|
||||
var R: any
|
||||
export default R = {
|
||||
"__esmodule": true,
|
||||
"__proto__": {}
|
||||
}
|
||||
|
||||
//// [m2.ts]
|
||||
import R from "./m1";
|
||||
const { __esmodule, __proto__ } = R;
|
||||
|
||||
|
||||
//// [m1.js]
|
||||
"use strict";
|
||||
var R;
|
||||
exports.__esModule = true;
|
||||
exports["default"] = R = {
|
||||
"__esmodule": true,
|
||||
"__proto__": {}
|
||||
};
|
||||
//// [m2.js]
|
||||
"use strict";
|
||||
var m1_1 = require("./m1");
|
||||
var __esmodule = m1_1["default"].__esmodule, __proto__ = m1_1["default"].__proto__;
|
||||
@ -0,0 +1,21 @@
|
||||
=== tests/cases/conformance/es6/modules/m1.ts ===
|
||||
|
||||
var R: any
|
||||
>R : Symbol(R, Decl(m1.ts, 1, 3))
|
||||
|
||||
export default R = {
|
||||
>R : Symbol(R, Decl(m1.ts, 1, 3))
|
||||
|
||||
"__esmodule": true,
|
||||
"__proto__": {}
|
||||
}
|
||||
|
||||
=== tests/cases/conformance/es6/modules/m2.ts ===
|
||||
import R from "./m1";
|
||||
>R : Symbol(R, Decl(m2.ts, 0, 6))
|
||||
|
||||
const { __esmodule, __proto__ } = R;
|
||||
>__esmodule : Symbol(__esmodule, Decl(m2.ts, 1, 7))
|
||||
>__proto__ : Symbol(__proto__, Decl(m2.ts, 1, 19))
|
||||
>R : Symbol(R, Decl(m2.ts, 0, 6))
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
=== tests/cases/conformance/es6/modules/m1.ts ===
|
||||
|
||||
var R: any
|
||||
>R : any
|
||||
|
||||
export default R = {
|
||||
>R = { "__esmodule": true, "__proto__": {}} : { "__esmodule": boolean; "__proto__": {}; }
|
||||
>R : any
|
||||
>{ "__esmodule": true, "__proto__": {}} : { "__esmodule": boolean; "__proto__": {}; }
|
||||
|
||||
"__esmodule": true,
|
||||
>true : boolean
|
||||
|
||||
"__proto__": {}
|
||||
>{} : {}
|
||||
}
|
||||
|
||||
=== tests/cases/conformance/es6/modules/m2.ts ===
|
||||
import R from "./m1";
|
||||
>R : { "__esmodule": boolean; "__proto__": {}; }
|
||||
|
||||
const { __esmodule, __proto__ } = R;
|
||||
>__esmodule : boolean
|
||||
>__proto__ : {}
|
||||
>R : { "__esmodule": boolean; "__proto__": {}; }
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
//// [tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores3.ts] ////
|
||||
|
||||
//// [m1.ts]
|
||||
|
||||
var R: any
|
||||
export default R = {
|
||||
"___": 30,
|
||||
"___hello": 21,
|
||||
"_hi": 40,
|
||||
}
|
||||
|
||||
//// [m2.ts]
|
||||
import R from "./m1";
|
||||
const { ___, ___hello, _hi } = R;
|
||||
|
||||
|
||||
//// [m1.js]
|
||||
"use strict";
|
||||
var R;
|
||||
exports.__esModule = true;
|
||||
exports["default"] = R = {
|
||||
"___": 30,
|
||||
"___hello": 21,
|
||||
"_hi": 40
|
||||
};
|
||||
//// [m2.js]
|
||||
"use strict";
|
||||
var m1_1 = require("./m1");
|
||||
var ___ = m1_1["default"].___, ___hello = m1_1["default"].___hello, _hi = m1_1["default"]._hi;
|
||||
@ -0,0 +1,23 @@
|
||||
=== tests/cases/conformance/es6/modules/m1.ts ===
|
||||
|
||||
var R: any
|
||||
>R : Symbol(R, Decl(m1.ts, 1, 3))
|
||||
|
||||
export default R = {
|
||||
>R : Symbol(R, Decl(m1.ts, 1, 3))
|
||||
|
||||
"___": 30,
|
||||
"___hello": 21,
|
||||
"_hi": 40,
|
||||
}
|
||||
|
||||
=== tests/cases/conformance/es6/modules/m2.ts ===
|
||||
import R from "./m1";
|
||||
>R : Symbol(R, Decl(m2.ts, 0, 6))
|
||||
|
||||
const { ___, ___hello, _hi } = R;
|
||||
>___ : Symbol(___, Decl(m2.ts, 1, 7))
|
||||
>___hello : Symbol(___hello, Decl(m2.ts, 1, 12))
|
||||
>_hi : Symbol(_hi, Decl(m2.ts, 1, 22))
|
||||
>R : Symbol(R, Decl(m2.ts, 0, 6))
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
=== tests/cases/conformance/es6/modules/m1.ts ===
|
||||
|
||||
var R: any
|
||||
>R : any
|
||||
|
||||
export default R = {
|
||||
>R = { "___": 30, "___hello": 21, "_hi": 40,} : { "___": number; "___hello": number; "_hi": number; }
|
||||
>R : any
|
||||
>{ "___": 30, "___hello": 21, "_hi": 40,} : { "___": number; "___hello": number; "_hi": number; }
|
||||
|
||||
"___": 30,
|
||||
>30 : number
|
||||
|
||||
"___hello": 21,
|
||||
>21 : number
|
||||
|
||||
"_hi": 40,
|
||||
>40 : number
|
||||
}
|
||||
|
||||
=== tests/cases/conformance/es6/modules/m2.ts ===
|
||||
import R from "./m1";
|
||||
>R : { "___": number; "___hello": number; "_hi": number; }
|
||||
|
||||
const { ___, ___hello, _hi } = R;
|
||||
>___ : number
|
||||
>___hello : number
|
||||
>_hi : number
|
||||
>R : { "___": number; "___hello": number; "_hi": number; }
|
||||
|
||||
@ -0,0 +1,75 @@
|
||||
//// [tests/cases/conformance/es6/modules/exportsAndImportsWithUnderscores4.ts] ////
|
||||
|
||||
//// [m1.ts]
|
||||
|
||||
declare var console: any;
|
||||
export function _() {
|
||||
console.log("_");
|
||||
}
|
||||
export function __() {
|
||||
console.log("__");
|
||||
}
|
||||
export function ___() {
|
||||
console.log("___");
|
||||
}
|
||||
export function _hi() {
|
||||
console.log("_hi");
|
||||
}
|
||||
export function __proto() {
|
||||
console.log("__proto");
|
||||
}
|
||||
export function __esmodule() {
|
||||
console.log("__esmodule");
|
||||
}
|
||||
export function ___hello(){
|
||||
console.log("___hello");
|
||||
}
|
||||
|
||||
//// [m2.ts]
|
||||
import {_, __, ___hello, __esmodule, __proto, _hi} from "./m1";
|
||||
_();
|
||||
__();
|
||||
___hello();
|
||||
__esmodule();
|
||||
__proto();
|
||||
_hi();
|
||||
|
||||
//// [m1.js]
|
||||
"use strict";
|
||||
function _() {
|
||||
console.log("_");
|
||||
}
|
||||
exports._ = _;
|
||||
function __() {
|
||||
console.log("__");
|
||||
}
|
||||
exports.__ = __;
|
||||
function ___() {
|
||||
console.log("___");
|
||||
}
|
||||
exports.___ = ___;
|
||||
function _hi() {
|
||||
console.log("_hi");
|
||||
}
|
||||
exports._hi = _hi;
|
||||
function __proto() {
|
||||
console.log("__proto");
|
||||
}
|
||||
exports.__proto = __proto;
|
||||
function __esmodule() {
|
||||
console.log("__esmodule");
|
||||
}
|
||||
exports.__esmodule = __esmodule;
|
||||
function ___hello() {
|
||||
console.log("___hello");
|
||||
}
|
||||
exports.___hello = ___hello;
|
||||
//// [m2.js]
|
||||
"use strict";
|
||||
var m1_1 = require("./m1");
|
||||
m1_1._();
|
||||
m1_1.__();
|
||||
m1_1.___hello();
|
||||
m1_1.__esmodule();
|
||||
m1_1.__proto();
|
||||
m1_1._hi();
|
||||
@ -0,0 +1,75 @@
|
||||
=== tests/cases/conformance/es6/modules/m1.ts ===
|
||||
|
||||
declare var console: any;
|
||||
>console : Symbol(console, Decl(m1.ts, 1, 11))
|
||||
|
||||
export function _() {
|
||||
>_ : Symbol(_, Decl(m1.ts, 1, 25))
|
||||
|
||||
console.log("_");
|
||||
>console : Symbol(console, Decl(m1.ts, 1, 11))
|
||||
}
|
||||
export function __() {
|
||||
>__ : Symbol(__, Decl(m1.ts, 4, 1))
|
||||
|
||||
console.log("__");
|
||||
>console : Symbol(console, Decl(m1.ts, 1, 11))
|
||||
}
|
||||
export function ___() {
|
||||
>___ : Symbol(___, Decl(m1.ts, 7, 1))
|
||||
|
||||
console.log("___");
|
||||
>console : Symbol(console, Decl(m1.ts, 1, 11))
|
||||
}
|
||||
export function _hi() {
|
||||
>_hi : Symbol(_hi, Decl(m1.ts, 10, 1))
|
||||
|
||||
console.log("_hi");
|
||||
>console : Symbol(console, Decl(m1.ts, 1, 11))
|
||||
}
|
||||
export function __proto() {
|
||||
>__proto : Symbol(__proto, Decl(m1.ts, 13, 1))
|
||||
|
||||
console.log("__proto");
|
||||
>console : Symbol(console, Decl(m1.ts, 1, 11))
|
||||
}
|
||||
export function __esmodule() {
|
||||
>__esmodule : Symbol(__esmodule, Decl(m1.ts, 16, 1))
|
||||
|
||||
console.log("__esmodule");
|
||||
>console : Symbol(console, Decl(m1.ts, 1, 11))
|
||||
}
|
||||
export function ___hello(){
|
||||
>___hello : Symbol(___hello, Decl(m1.ts, 19, 1))
|
||||
|
||||
console.log("___hello");
|
||||
>console : Symbol(console, Decl(m1.ts, 1, 11))
|
||||
}
|
||||
|
||||
=== tests/cases/conformance/es6/modules/m2.ts ===
|
||||
import {_, __, ___hello, __esmodule, __proto, _hi} from "./m1";
|
||||
>_ : Symbol(_, Decl(m2.ts, 0, 8))
|
||||
>__ : Symbol(__, Decl(m2.ts, 0, 10))
|
||||
>___hello : Symbol(___hello, Decl(m2.ts, 0, 14))
|
||||
>__esmodule : Symbol(__esmodule, Decl(m2.ts, 0, 24))
|
||||
>__proto : Symbol(__proto, Decl(m2.ts, 0, 36))
|
||||
>_hi : Symbol(_hi, Decl(m2.ts, 0, 45))
|
||||
|
||||
_();
|
||||
>_ : Symbol(_, Decl(m2.ts, 0, 8))
|
||||
|
||||
__();
|
||||
>__ : Symbol(__, Decl(m2.ts, 0, 10))
|
||||
|
||||
___hello();
|
||||
>___hello : Symbol(___hello, Decl(m2.ts, 0, 14))
|
||||
|
||||
__esmodule();
|
||||
>__esmodule : Symbol(__esmodule, Decl(m2.ts, 0, 24))
|
||||
|
||||
__proto();
|
||||
>__proto : Symbol(__proto, Decl(m2.ts, 0, 36))
|
||||
|
||||
_hi();
|
||||
>_hi : Symbol(_hi, Decl(m2.ts, 0, 45))
|
||||
|
||||
@ -0,0 +1,109 @@
|
||||
=== tests/cases/conformance/es6/modules/m1.ts ===
|
||||
|
||||
declare var console: any;
|
||||
>console : any
|
||||
|
||||
export function _() {
|
||||
>_ : () => void
|
||||
|
||||
console.log("_");
|
||||
>console.log("_") : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>"_" : string
|
||||
}
|
||||
export function __() {
|
||||
>__ : () => void
|
||||
|
||||
console.log("__");
|
||||
>console.log("__") : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>"__" : string
|
||||
}
|
||||
export function ___() {
|
||||
>___ : () => void
|
||||
|
||||
console.log("___");
|
||||
>console.log("___") : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>"___" : string
|
||||
}
|
||||
export function _hi() {
|
||||
>_hi : () => void
|
||||
|
||||
console.log("_hi");
|
||||
>console.log("_hi") : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>"_hi" : string
|
||||
}
|
||||
export function __proto() {
|
||||
>__proto : () => void
|
||||
|
||||
console.log("__proto");
|
||||
>console.log("__proto") : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>"__proto" : string
|
||||
}
|
||||
export function __esmodule() {
|
||||
>__esmodule : () => void
|
||||
|
||||
console.log("__esmodule");
|
||||
>console.log("__esmodule") : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>"__esmodule" : string
|
||||
}
|
||||
export function ___hello(){
|
||||
>___hello : () => void
|
||||
|
||||
console.log("___hello");
|
||||
>console.log("___hello") : any
|
||||
>console.log : any
|
||||
>console : any
|
||||
>log : any
|
||||
>"___hello" : string
|
||||
}
|
||||
|
||||
=== tests/cases/conformance/es6/modules/m2.ts ===
|
||||
import {_, __, ___hello, __esmodule, __proto, _hi} from "./m1";
|
||||
>_ : () => void
|
||||
>__ : () => void
|
||||
>___hello : () => void
|
||||
>__esmodule : () => void
|
||||
>__proto : () => void
|
||||
>_hi : () => void
|
||||
|
||||
_();
|
||||
>_() : void
|
||||
>_ : () => void
|
||||
|
||||
__();
|
||||
>__() : void
|
||||
>__ : () => void
|
||||
|
||||
___hello();
|
||||
>___hello() : void
|
||||
>___hello : () => void
|
||||
|
||||
__esmodule();
|
||||
>__esmodule() : void
|
||||
>__esmodule : () => void
|
||||
|
||||
__proto();
|
||||
>__proto() : void
|
||||
>__proto : () => void
|
||||
|
||||
_hi();
|
||||
>_hi() : void
|
||||
>_hi : () => void
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
//@module: commonjs
|
||||
//@target: ES3
|
||||
|
||||
// @filename: m1.ts
|
||||
var R: any
|
||||
export default R = {
|
||||
"__": 20,
|
||||
"_": 10
|
||||
"___": 30
|
||||
}
|
||||
|
||||
// @filename: m2.ts
|
||||
import R from "./m1";
|
||||
const { __, _, ___ } = R;
|
||||
@ -0,0 +1,13 @@
|
||||
//@module: commonjs
|
||||
//@target: ES3
|
||||
|
||||
// @filename: m1.ts
|
||||
var R: any
|
||||
export default R = {
|
||||
"__esmodule": true,
|
||||
"__proto__": {}
|
||||
}
|
||||
|
||||
// @filename: m2.ts
|
||||
import R from "./m1";
|
||||
const { __esmodule, __proto__ } = R;
|
||||
@ -0,0 +1,14 @@
|
||||
//@module: commonjs
|
||||
//@target: ES3
|
||||
|
||||
// @filename: m1.ts
|
||||
var R: any
|
||||
export default R = {
|
||||
"___": 30,
|
||||
"___hello": 21,
|
||||
"_hi": 40,
|
||||
}
|
||||
|
||||
// @filename: m2.ts
|
||||
import R from "./m1";
|
||||
const { ___, ___hello, _hi } = R;
|
||||
@ -0,0 +1,35 @@
|
||||
//@module: commonjs
|
||||
//@target: ES3
|
||||
|
||||
// @filename: m1.ts
|
||||
declare var console: any;
|
||||
export function _() {
|
||||
console.log("_");
|
||||
}
|
||||
export function __() {
|
||||
console.log("__");
|
||||
}
|
||||
export function ___() {
|
||||
console.log("___");
|
||||
}
|
||||
export function _hi() {
|
||||
console.log("_hi");
|
||||
}
|
||||
export function __proto() {
|
||||
console.log("__proto");
|
||||
}
|
||||
export function __esmodule() {
|
||||
console.log("__esmodule");
|
||||
}
|
||||
export function ___hello(){
|
||||
console.log("___hello");
|
||||
}
|
||||
|
||||
// @filename: m2.ts
|
||||
import {_, __, ___hello, __esmodule, __proto, _hi} from "./m1";
|
||||
_();
|
||||
__();
|
||||
___hello();
|
||||
__esmodule();
|
||||
__proto();
|
||||
_hi();
|
||||
Loading…
x
Reference in New Issue
Block a user