-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove duplicate function createTextRange #23346
Conversation
src/compiler/utilities.ts
Outdated
@@ -3686,7 +3686,8 @@ namespace ts { | |||
* @param pos The start position. | |||
* @param end The end position. | |||
*/ | |||
export function createRange(pos: number, end: number): TextRange { | |||
export function createRange(pos: number, end: number = pos, noAssert = false): TextRange { | |||
Debug.assert(noAssert || end >= pos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We treat -1
as a special value to indicate a synthetic position. Rather than adding a noAssert
, we could just write:
Debug.assert(pos === -1 || end === -1 || end >= pos);
src/compiler/transformers/es2015.ts
Outdated
@@ -2075,7 +2075,7 @@ namespace ts { | |||
const firstDeclaration = firstOrUndefined(declarations); | |||
if (firstDeclaration) { | |||
const lastDeclaration = lastOrUndefined(declarations); | |||
setSourceMapRange(declarationList, createRange(firstDeclaration.pos, lastDeclaration.end)); | |||
setSourceMapRange(declarationList, createRange(firstDeclaration.pos, lastDeclaration.end, /*noAssert*/ true)); // TODO: GH#23370 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We sometimes insert temp variables into the declaration list, and the first temp we insert caches the initializer on the RHS. Since all we care about is inserting a mapping at the beginning and end of the list, we could probably just change this to:
if (declarations.length) {
const range = reduceLeft(declarations, (range, node) => {
range.pos = range.pos === -1 ? node.pos : node.pos === -1 ? range.pos : Math.min(range.pos, node.pos);
range.end = range.end === -1 ? node.end : node.end === -1 ? range.end : Math.max(range.end, node.end);
return range;
}, createRange(-1, -1));
setSourceMapRange(declarationList, range);
}
Though we would need to verify the results in the debugger.
@rbuckton Tried that out and there were some baseline changes -- not sure if good or bad. |
@Andy-MS Try stepping through an example in a debugger using source maps to see if the mappings make sense. |
It looks correct. For a simple example: var { a, b } = 0; The output is: var _a = 0, a = _a.a, b = _a.b; The old source map is:
The new source map is:
The difference being Also tested with debugging in vscode with an ES5 target, stepping "into" at every opportunity in the following example: function f() {
return {
get a() {
return 0;
},
get b() {
return 0;
}
}
}
const { a, b } = f(); In both cases, the places the cursor moved to were the same:
|
@rbuckton Good to go? |
@rbuckton Please review |
@Andy-MS please merge at your leisure |
This is the same as
createRange
.