microsoft / microsoft/TypeScript

Generator helper should include [Symbol.toStringTag]

Abierto
#35,833 8 comentarios 2 reacciones 1 asignado Ver en GitHub

@rbuckton ya está trabajando en esto.

Desde el 14/1/2020.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

TypeScript Version: 3.8.0-dev.20191223 and 3.7.3

Search Terms:

Generator, toStringTag, transformer, helper, tslib

Code

The following code will error in when using compilerOptions.target = es5, but works correctly when compiled with target = es2015 or greater.

// index.ts
function* f() {}
if (f()[Symbol.toStringTag] !== 'Generator') {
	  throw new Error("Bad generator!")
}
console.log('👍 Works well!');
tsc --target es5 --lib dom,es5,es2015 ./index.ts && node index.js
# Error: Bad generator!
tsc --target es2015 ./index.ts && node index.js
# 👍Works well!

Expected behavior:

The property should be set as expected via the helpers.

Generators should include the Symbol.toStringTag property "Generator" according to spec.

Some libraries check for a generator by inspecting this property. For example, @wordpress/redux-routine checks for this property and does not correctly handle generators produced by the helper.

regenerator-runtime is a widely used generator helper which does set this property.

Actual behavior:

Symbol.toStringTag is not included on the generator.

Playground Link:

Broken with target=es5
Working with target=es2015

Related Issues:

#19006

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.