Skip to content

Commit

Permalink
Handle error spans on manufactured checked nodes, add petit-dom test …
Browse files Browse the repository at this point in the history
…(its nice and small)
  • Loading branch information
weswigham committed Feb 28, 2019
1 parent 3c6dc4e commit cec5c8d
Show file tree
Hide file tree
Showing 6 changed files with 5,589 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18764,6 +18764,7 @@ namespace ts {
// Fake up a property declaration for the children
childrenPropSymbol.valueDeclaration = createPropertySignature(/*modifiers*/ undefined, unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined);
childrenPropSymbol.valueDeclaration.parent = attributes;
childrenPropSymbol.valueDeclaration.original = parent;
childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol;
const childPropMap = createSymbolTable();
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
Expand Down Expand Up @@ -20307,6 +20308,7 @@ namespace ts {

function createSyntheticExpression(parent: Node, type: Type | ((mode: CheckMode | undefined) => Type), isSpread?: boolean) {
const result = <SyntheticExpression>createNode(SyntaxKind.SyntheticExpression, parent.pos, parent.end);
result.original = parent;
result.parent = parent;
result.type = type;
result.isSpread = isSpread || false;
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,11 @@ namespace ts {
export function getSourceFileOfNode(node: Node): SourceFile;
export function getSourceFileOfNode(node: Node | undefined): SourceFile | undefined;
export function getSourceFileOfNode(node: Node): SourceFile {
const root = node;
while (node && node.kind !== SyntaxKind.SourceFile) {
node = node.parent;
}
return <SourceFile>node;
return <SourceFile>node || (root && root.original && getSourceFileOfNode(root.original));
}

export function isStatementWithLocals(node: Node) {
Expand Down Expand Up @@ -849,6 +850,9 @@ namespace ts {
}

export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan {
while (node.original) {
node = node.original;
}
let errorNode: Node | undefined = node;
switch (node.kind) {
case SyntaxKind.SourceFile:
Expand Down Expand Up @@ -2927,6 +2931,7 @@ namespace ts {
case SyntaxKind.TemplateExpression:
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.OmittedExpression:
case SyntaxKind.SyntheticExpression:
return 20;

default:
Expand Down
Loading

0 comments on commit cec5c8d

Please sign in to comment.