Skip to content

String escape conversion can create accidental octal literal #17226

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
alangpierce opened this issue Jul 15, 2017 · 1 comment
Closed

String escape conversion can create accidental octal literal #17226

alangpierce opened this issue Jul 15, 2017 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@alangpierce
Copy link
Contributor

TypeScript Version: 2.4.1

Code

"use strict"
console.log(`\x001`);

Playground link

Expected behavior:

Produces code that prints a null character followed by 1.

Actual behavior:

Produces this code:

"use strict";
console.log("\01");

This crashes because \01 is an octal literal, which isn't allowed in strict mode.

Note that this TypeScript code fails in a similar way:

console.log(`\u00001`);

Context:

This came up when converting the decaffeinate test suite to TypeScript, and the test case was based on a test from the CoffeeScript test suite. The CoffeeScript test suite has lots of edge cases like this, so I don't necessarily think this bug is likely to come up in real production code, but still would be good to fix. I was able to work around the issue (diff), so it's not blocking me, but CoffeeScript and Babel handle this sort of thing, so would be good if TypeScript did as well.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Aug 23, 2017
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.6 milestone Aug 23, 2017
@DanielRosenwasser
Copy link
Member

Sorry for the delay, thanks for reporting!

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Aug 24, 2017
@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
Projects
None yet
Development

No branches or pull requests

4 participants