On 2.6.1. Copy the following into a repro.ts file:
import * as ts from 'typescript';
export function transformSourceFile(context: ts.TransformationContext): ts.Transformer<ts.SourceFile> {
function createFunction(name: string, statements: ts.Statement[]): ts.FunctionDeclaration {
return ts.createFunctionDeclaration(
[],
[],
undefined,
name,
[],
[],
ts.createTypeReferenceNode('void', []),
ts.createBlock(statements));
}
return (sourceFile: ts.SourceFile) => {
return ts.updateSourceFileNode(sourceFile, [createFunction('foo', []), ...sourceFile.statements]);
};
}
const options: ts.CompilerOptions = {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS
}
const program = ts.createProgram(['repro.ts'], options);
const hello = program.getSourceFile('repro.ts');
function transform(source: ts.SourceFile): ts.SourceFile {
const result = ts.transform(source, [transformSourceFile]);
const transformedSource = result.transformed[0];
result.dispose();
return transformedSource;
}
const transformed = transform(hello);
transformed.getChildren();
Expected behavior:
No exception
Actual behavior:
/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:3652
throw e;
^
Error: Debug Failure. False expression.
at Object.setTextPos (/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:7214:22)
at SourceFileObject.NodeObject.addSyntheticNodes (/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:94584:24)
at SourceFileObject.NodeObject.createSyntaxList (/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:94605:32)
at processNodes (/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:94640:37)
at visitNodes (/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:12639:24)
at Object.forEachChild (/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:12821:24)
at SourceFileObject.NodeObject.createChildren (/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:94654:16)
at SourceFileObject.NodeObject.getChildren (/Users/jbevain/tmp/reprots/node_modules/typescript/lib/typescript.js:94673:22)
at Object.<anonymous> (/Users/jbevain/tmp/reprots/repro.js:26:13)
at Module._compile (module.js:624:30)
On 2.6.1. Copy the following into a repro.ts file:
Expected behavior:
No exception
Actual behavior: