Fix source map scope name for computed properties

This commit is contained in:
Jason Freeman
2015-01-21 11:01:05 -08:00
parent eb7798fbb2
commit de5aa6c0d2
11 changed files with 266 additions and 3 deletions

View File

@@ -1734,7 +1734,14 @@ module ts {
if (scopeName) {
var parentIndex = getSourceMapNameIndex();
if (parentIndex !== -1) {
scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName;
// Child scopes are always shown with a dot (even if they have no name),
// unless it is a computed property. Then it is shown with brackets,
// but the brackets are included in the name.
var name = (<Declaration>node).name;
if (!name || name.kind !== SyntaxKind.ComputedPropertyName) {
scopeName = "." + scopeName;
}
scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName;
}
scopeNameIndex = getProperty(sourceMapNameIndexMap, scopeName);
@@ -1762,8 +1769,11 @@ module ts {
node.kind === SyntaxKind.EnumDeclaration) {
// Declaration and has associated name use it
if ((<Declaration>node).name) {
// TODO(jfreeman): Ask shkamat about what this name should be for source maps
scopeName = (<Identifier>(<Declaration>node).name).text;
var name = (<Declaration>node).name;
// For computed property names, the text will include the brackets
scopeName = name.kind === SyntaxKind.ComputedPropertyName
? getTextOfNode(name)
: (<Identifier>(<Declaration>node).name).text;
}
recordScopeNameStart(scopeName);
}

View File

@@ -0,0 +1,17 @@
//// [computedPropertyNamesSourceMap1.ts]
class C {
["hello"]() {
debugger;
}
}
//// [computedPropertyNamesSourceMap1.js]
var C = (function () {
function C() {
}
C.prototype["hello"] = function () {
debugger;
};
return C;
})();
//# sourceMappingURL=computedPropertyNamesSourceMap1.js.map

View File

@@ -0,0 +1,2 @@
//// [computedPropertyNamesSourceMap1.js.map]
{"version":3,"file":"computedPropertyNamesSourceMap1.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA,IAAM,CAAC;IAAPA,SAAMA,CAACA;IAIPC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"}

View File

@@ -0,0 +1,114 @@
===================================================================
JsFile: computedPropertyNamesSourceMap1.js
mapUrl: computedPropertyNamesSourceMap1.js.map
sourceRoot:
sources: computedPropertyNamesSourceMap1.ts
===================================================================
-------------------------------------------------------------------
emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1.js
sourceFile:computedPropertyNamesSourceMap1.ts
-------------------------------------------------------------------
>>>var C = (function () {
1 >
2 >^^^^
3 > ^
4 > ^^^^^^^^^^^^^^->
1 >
2 >class
3 > C
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 5) Source(1, 7) + SourceIndex(0)
3 >Emitted(1, 6) Source(1, 8) + SourceIndex(0)
---
>>> function C() {
1->^^^^
2 > ^^^^^^^^^
3 > ^
1->
2 > class
3 > C
1->Emitted(2, 5) Source(1, 1) + SourceIndex(0) name (C)
2 >Emitted(2, 14) Source(1, 7) + SourceIndex(0) name (C)
3 >Emitted(2, 15) Source(1, 8) + SourceIndex(0) name (C)
---
>>> }
1 >^^^^
2 > ^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 > {
> ["hello"]() {
> debugger;
> }
>
2 > }
1 >Emitted(3, 5) Source(5, 1) + SourceIndex(0) name (C.constructor)
2 >Emitted(3, 6) Source(5, 2) + SourceIndex(0) name (C.constructor)
---
>>> C.prototype["hello"] = function () {
1->^^^^
2 > ^^^^^^^^^^^^
3 > ^^^^^^^
4 > ^
5 > ^^^
1->
2 > [
3 > "hello"
4 > ]
5 >
1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C)
2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C)
3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C)
4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C)
5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C)
---
>>> debugger;
1 >^^^^^^^^
2 > ^^^^^^^^
3 > ^
1 >["hello"]() {
>
2 > debugger
3 > ;
1 >Emitted(5, 9) Source(3, 9) + SourceIndex(0) name (C["hello"])
2 >Emitted(5, 17) Source(3, 17) + SourceIndex(0) name (C["hello"])
3 >Emitted(5, 18) Source(3, 18) + SourceIndex(0) name (C["hello"])
---
>>> };
1 >^^^^
2 > ^
3 > ^^^^^^^^^->
1 >
>
2 > }
1 >Emitted(6, 5) Source(4, 5) + SourceIndex(0) name (C["hello"])
2 >Emitted(6, 6) Source(4, 6) + SourceIndex(0) name (C["hello"])
---
>>> return C;
1->^^^^
2 > ^^^^^^^^
1->
>
2 > }
1->Emitted(7, 5) Source(5, 1) + SourceIndex(0) name (C)
2 >Emitted(7, 13) Source(5, 2) + SourceIndex(0) name (C)
---
>>>})();
1 >
2 >^
3 >
4 > ^^^^
5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
2 >}
3 >
4 > class C {
> ["hello"]() {
> debugger;
> }
> }
1 >Emitted(8, 1) Source(5, 1) + SourceIndex(0) name (C)
2 >Emitted(8, 2) Source(5, 2) + SourceIndex(0) name (C)
3 >Emitted(8, 2) Source(1, 1) + SourceIndex(0)
4 >Emitted(8, 6) Source(5, 2) + SourceIndex(0)
---
>>>//# sourceMappingURL=computedPropertyNamesSourceMap1.js.map

View File

@@ -0,0 +1,8 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1.ts ===
class C {
>C : C
["hello"]() {
debugger;
}
}

View File

@@ -0,0 +1,14 @@
//// [computedPropertyNamesSourceMap2.ts]
var v = {
["hello"]() {
debugger;
}
}
//// [computedPropertyNamesSourceMap2.js]
var v = {
["hello"]() {
debugger;
}
};
//# sourceMappingURL=computedPropertyNamesSourceMap2.js.map

View File

@@ -0,0 +1,2 @@
//// [computedPropertyNamesSourceMap2.js.map]
{"version":3,"file":"computedPropertyNamesSourceMap2.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2.ts"],"names":["[\"hello\"]"],"mappings":"AAAA,IAAI,CAAC,GAAG;IACJ,CAAC,OAAO,CAAC;QACLA,QAAQA,CAACA;IACbA,CAACA;CACJ,CAAA"}

View File

@@ -0,0 +1,73 @@
===================================================================
JsFile: computedPropertyNamesSourceMap2.js
mapUrl: computedPropertyNamesSourceMap2.js.map
sourceRoot:
sources: computedPropertyNamesSourceMap2.ts
===================================================================
-------------------------------------------------------------------
emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2.js
sourceFile:computedPropertyNamesSourceMap2.ts
-------------------------------------------------------------------
>>>var v = {
1 >
2 >^^^^
3 > ^
4 > ^^^
5 > ^^^^^^^^^^->
1 >
2 >var
3 > v
4 > =
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0)
4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0)
---
>>> ["hello"]() {
1->^^^^
2 > ^
3 > ^^^^^^^
4 > ^
5 > ^^^^^->
1->{
>
2 > [
3 > "hello"
4 > ]
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0)
2 >Emitted(2, 6) Source(2, 6) + SourceIndex(0)
3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0)
4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0)
---
>>> debugger;
1->^^^^^^^^
2 > ^^^^^^^^
3 > ^
1->() {
>
2 > debugger
3 > ;
1->Emitted(3, 9) Source(3, 9) + SourceIndex(0) name (["hello"])
2 >Emitted(3, 17) Source(3, 17) + SourceIndex(0) name (["hello"])
3 >Emitted(3, 18) Source(3, 18) + SourceIndex(0) name (["hello"])
---
>>> }
1 >^^^^
2 > ^
1 >
>
2 > }
1 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (["hello"])
2 >Emitted(4, 6) Source(4, 6) + SourceIndex(0) name (["hello"])
---
>>>};
1 >^
2 > ^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
>}
2 >
1 >Emitted(5, 2) Source(5, 2) + SourceIndex(0)
2 >Emitted(5, 3) Source(5, 2) + SourceIndex(0)
---
>>>//# sourceMappingURL=computedPropertyNamesSourceMap2.js.map

View File

@@ -0,0 +1,9 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2.ts ===
var v = {
>v : {}
>{ ["hello"]() { debugger; }} : {}
["hello"]() {
debugger;
}
}

View File

@@ -0,0 +1,7 @@
// @target: es6
// @sourceMap: true
class C {
["hello"]() {
debugger;
}
}

View File

@@ -0,0 +1,7 @@
// @target: es6
// @sourceMap: true
var v = {
["hello"]() {
debugger;
}
}