Skip to content

--target ES5 does not compile ES5-compatible code (String.prototype.repeat) when libs are used #25853

@agoldis

Description

@agoldis

TypeScript Version: Version 2.9.2

Search Terms:
es5 string.prototype.repeat

Code

'a'.repeat(10);

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "./build",
    "target": "es5",
    "lib": ["es6", "dom"],
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "./",
  },
  "exclude": [
    "node_modules",
    "build"
  ]
}

Expected behavior:
Expecting String.prototype.repeat to be polyfilled or rewritten in the same manner that async/await syntax in transpiled correctly because the target is es5 and String.prototype.repeat is not part of ES5.

That is according to documentation

--target: Specify ECMAScript target version: "ES3" (default), "ES5", "ES6"/"ES2015", "ES2016", "ES2017" or "ESNext".

Actual behavior:
The expression appears as is

Playground Link:
https://github.com/agoldis/typescript-25853

Related Issues:
#3101

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions