Skip to content

Commit cec5c8d

Browse files
committed
Handle error spans on manufactured checked nodes, add petit-dom test (its nice and small)
1 parent 3c6dc4e commit cec5c8d

File tree

6 files changed

+5589
-1
lines changed

6 files changed

+5589
-1
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18764,6 +18764,7 @@ namespace ts {
1876418764
// Fake up a property declaration for the children
1876518765
childrenPropSymbol.valueDeclaration = createPropertySignature(/*modifiers*/ undefined, unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined);
1876618766
childrenPropSymbol.valueDeclaration.parent = attributes;
18767+
childrenPropSymbol.valueDeclaration.original = parent;
1876718768
childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol;
1876818769
const childPropMap = createSymbolTable();
1876918770
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
@@ -20307,6 +20308,7 @@ namespace ts {
2030720308

2030820309
function createSyntheticExpression(parent: Node, type: Type | ((mode: CheckMode | undefined) => Type), isSpread?: boolean) {
2030920310
const result = <SyntheticExpression>createNode(SyntaxKind.SyntheticExpression, parent.pos, parent.end);
20311+
result.original = parent;
2031020312
result.parent = parent;
2031120313
result.type = type;
2031220314
result.isSpread = isSpread || false;

src/compiler/utilities.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,11 @@ namespace ts {
312312
export function getSourceFileOfNode(node: Node): SourceFile;
313313
export function getSourceFileOfNode(node: Node | undefined): SourceFile | undefined;
314314
export function getSourceFileOfNode(node: Node): SourceFile {
315+
const root = node;
315316
while (node && node.kind !== SyntaxKind.SourceFile) {
316317
node = node.parent;
317318
}
318-
return <SourceFile>node;
319+
return <SourceFile>node || (root && root.original && getSourceFileOfNode(root.original));
319320
}
320321

321322
export function isStatementWithLocals(node: Node) {
@@ -849,6 +850,9 @@ namespace ts {
849850
}
850851

851852
export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan {
853+
while (node.original) {
854+
node = node.original;
855+
}
852856
let errorNode: Node | undefined = node;
853857
switch (node.kind) {
854858
case SyntaxKind.SourceFile:
@@ -2927,6 +2931,7 @@ namespace ts {
29272931
case SyntaxKind.TemplateExpression:
29282932
case SyntaxKind.ParenthesizedExpression:
29292933
case SyntaxKind.OmittedExpression:
2934+
case SyntaxKind.SyntheticExpression:
29302935
return 20;
29312936

29322937
default:

0 commit comments

Comments
 (0)