Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Downlevel emit for template strings should use 'void 0' not 'undefined' #38430

Closed
rbuckton opened this issue May 8, 2020 · 2 comments · Fixed by #38439
Closed

Downlevel emit for template strings should use 'void 0' not 'undefined' #38430

rbuckton opened this issue May 8, 2020 · 2 comments · Fixed by #38439
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this

Comments

@rbuckton
Copy link
Member

rbuckton commented May 8, 2020

TypeScript Version: 3.9.x, 4.0.x-dev

Search Terms: template string emit

Code

From ~/tests/cases/conformance/es2018/invalidTaggedTemplateEscapeSequences.ts:

const x = tag`\u{hello} ${ 100 } \xtraordinary ${ 200 } wonderful ${ 300 } \uworld`;

Expected behavior:

ES5/ES3 emit:

const x = tag(__makeTemplateObject([void 0, void 0, " wonderful ", void 0], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);

Actual behavior:

ES5/ES3 emit:

const x = tag(__makeTemplateObject([undefined, undefined, " wonderful ", undefined], ["\\u{hello} ", " \\xtraordinary ", " wonderful ", " \\uworld"]), 100, 200, 300);

In ES5, undefined is an identifier and not a keyword and can be redeclared. In ES3, undefined isn't declared. In general we emit void 0 in these cases.

This can be easily addressed by changing createTemplateCooked in ~/src/compiler/transformers/taggedTemplate.ts to return createVoidZero() instead of createIdentifier("undefined") when a template contains an invalid escape sequence..

Playground Link: link

Related Issues: #23801, #12700

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label May 8, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 8, 2020
@DanielRosenwasser DanielRosenwasser added Good First Issue Well scoped, documented and has the green light Help Wanted You can do this labels May 9, 2020
@lissein
Copy link
Contributor

lissein commented May 9, 2020

Hi, I'll work on this if it's ok.

DanielRosenwasser added a commit that referenced this issue May 12, 2020
Changed template strings to emit void 0 instead of undefined (#38430)
@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label May 12, 2020
@DanielRosenwasser
Copy link
Member

Thanks @lissein!

cangSDARM added a commit to cangSDARM/TypeScript that referenced this issue May 12, 2020
* upstream/master: (54 commits)
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  Fix for jsdoc modifiers on constructor params (microsoft#38403)
  Improve assert message in binder (microsoft#38270)
  fix broken regex on "src/services/completions.ts#getCompletionData" (microsoft#37546)
  report error for duplicate @type declaration (microsoft#38340)
  fix(38073): hide 'Extract to function in global scope' action for arrow functions which use 'this' (microsoft#38107)
  Update user baselines (microsoft#38472)
  Update user baselines (microsoft#38405)
  Changed template strings to emit void 0 instead of undefined (microsoft#38430)
  Fix js missing type arguments on existing nodes and jsdoc object literal declaration emit (microsoft#38368)
  LEGO: check in for master to temporary branch.
  Make isDynamicFileName available publicly (microsoft#38269)
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  Exclude arrays and tuples from full intersection property check (microsoft#38395)
  Fix crash caused by assertion with evolving array type (microsoft#38398)
  Update user baselines (microsoft#38128)
  LEGO: check in for master to temporary branch.
  moveToNewFile: handle namespace imports too
  ...

# Conflicts:
#	src/compiler/types.ts
#	src/compiler/utilities.ts
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants