Skip to content

Printer fails when encountering RegularExpressionLiteral #18071

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

Closed
fwouts opened this issue Aug 27, 2017 · 3 comments
Closed

Printer fails when encountering RegularExpressionLiteral #18071

fwouts opened this issue Aug 27, 2017 · 3 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@fwouts
Copy link

fwouts commented Aug 27, 2017

TypeScript Version: 2.4.2

Code

import * as ts from "typescript";
let sourceCode = "let a = /regexp/";
let tsSourceFile = ts.createSourceFile(
  "script.js",
  sourceCode,
  ts.ScriptTarget.Latest
);
console.log(
  ts.createPrinter().printFile(tsSourceFile)
);

Expected behavior:
The script should output let a = /regexp/;

Actual behavior:
The script crashes with the following stack trace:

.../node_modules/typescript/lib/typescript.js:3495
            throw e;
            ^
Error: Debug Failure.
    at Object.getLiteralText (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:7077:18)
    at getLiteralTextOfNode (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:68597:23)
    at emitLiteral (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:66918:24)
    at pipelineEmitExpression (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:66816:28)
    at pipelineEmitWithHint (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:66565:49)
    at pipelineEmitWithSourceMap (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:66558:17)
    at emitNodeWithNestedComments (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:64324:17)
    at emitNodeWithSynthesizedComments (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:64274:13)
    at emitNodeWithComments (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:64244:21)
    at pipelineEmitWithComments (/Users/work/GitHub/sample-js-selfparsing/node_modules/typescript/lib/typescript.js:66547:17)
error Command failed with exit code 1.

Proposed fix:
fwouts@884cadf

Where would be a good place to add tests for this?

@ikatyang
Copy link
Contributor

ikatyang commented Aug 27, 2017

https://github.com/Microsoft/TypeScript/blob/master/src/harness/unittests/printer.ts

fwouts pushed a commit to fwouts/TypeScript that referenced this issue Aug 27, 2017
@fwouts
Copy link
Author

fwouts commented Aug 27, 2017

Thanks @ikatyang, I've added a test in fwouts@170bc6f.

Happy to send a PR once the Community milestone is added to this issue.

@DanielRosenwasser DanielRosenwasser added this to the Community milestone Aug 27, 2017
@DanielRosenwasser DanielRosenwasser added Help Wanted You can do this Bug A bug in TypeScript labels Aug 27, 2017
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Aug 27, 2017

Go for it! Thanks for looking into this @fwouts and being mindful of the triage process.

@ikatyang, thanks for helping @fwouts out. 😃

@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Aug 28, 2017
@DanielRosenwasser DanielRosenwasser modified the milestones: TypeScript 2.6, Community Aug 28, 2017
DanielRosenwasser added a commit that referenced this issue Aug 28, 2017
Fix #18071: Printer failure when encountering RegularExpressionLiteral
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants