Skip to content

Commit

Permalink
[ts] enable support for iterators in browsers (#22986)
Browse files Browse the repository at this point in the history
I was surprised when I tried to spread a `Set` in TypeScript and the browser complained about `Set.slice()` not being defined. This is because TypeScript does not automatically enable support for iterators when targeting earlier ES versions, like we do in the browser, unless you use the `"downlevelIteration": true` compiler option. This injects some helpers into the necessary files for reading/spreading iterators, which can be stuffed behind an import statement with using the `"importHelpers": true` compiler option and include `tslib` in our dependencies. This is already a dependency of several of our packages, so it shouldn't cause any additional modules.
  • Loading branch information
Spencer authored Sep 13, 2018
1 parent 01ee574 commit b55705e
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"topojson-client": "3.0.0",
"trunc-html": "1.0.2",
"trunc-text": "1.0.2",
"tslib": "^1.9.3",
"type-detect": "^4.0.8",
"uglifyjs-webpack-plugin": "^1.2.7",
"ui-select": "0.19.6",
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-datemath/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"babel-preset-env": "^1.6.1"
},
"dependencies": {
"moment": "^2.13.0"
"moment": "^2.13.0",
"tslib": "^1.9.3"
}
}
4 changes: 4 additions & 0 deletions packages/kbn-datemath/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,10 @@ trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"

tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

tunnel-agent@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"execa": "^0.10.0",
"moment": "^2.20.1",
"rxjs": "^6.2.1",
"tree-kill": "^1.2.0"
"tree-kill": "^1.2.0",
"tslib": "^1.9.3"
},
"devDependencies": {
"@kbn/babel-preset": "link:../kbn-babel-preset",
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-dev-utils/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1797,9 +1797,9 @@ trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"

tslib@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
tslib@^1.9.0, tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

tunnel-agent@^0.6.0:
version "0.6.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-es/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ tslib@^1.9.0:
version "1.9.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.2.tgz#8be0cc9a1f6dc7727c38deb16c2ebd1a2892988e"

tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-i18n/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,10 @@ tslib@^1.9.0:
version "1.9.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.2.tgz#8be0cc9a1f6dc7727c38deb16c2ebd1a2892988e"

tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

ua-parser-js@^0.7.9:
version "0.7.18"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.18.tgz#a7bfd92f56edfb117083b69e31d2aa8882d4b1ed"
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-pm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@
"webpack": "^3.11.0",
"wrap-ansi": "^3.0.1",
"write-pkg": "^3.1.0"
},
"dependencies": {
"tslib": "^1.9.3"
}
}
6 changes: 3 additions & 3 deletions packages/kbn-pm/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3570,9 +3570,9 @@ ts-loader@^3.5.0:
micromatch "^3.1.4"
semver "^5.0.1"

tslib@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
tslib@^1.9.0, tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

[email protected]:
version "0.0.0"
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-system-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"devDependencies": {
"@types/jest": "^23.3.1",
"typescript": "^3.0.3"
},
"dependencies": {
"tslib": "^1.9.3"
}
}
4 changes: 4 additions & 0 deletions packages/kbn-system-loader/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
version "23.3.1"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.1.tgz#a4319aedb071d478e6f407d1c4578ec8156829cf"

tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

typescript@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8"
4 changes: 4 additions & 0 deletions packages/kbn-test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,10 @@ tslib@^1.9.0:
version "1.9.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.1.tgz#a5d1f0532a49221c87755cfcc89ca37197242ba7"

tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

user-home@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190"
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@

// Forbid unused local variables as the rule was deprecated by ts-lint
"noUnusedLocals": true,

// Provide full support for iterables in for..of, spread and destructuring when targeting ES5 or ES3.
"downlevelIteration": true,

// import tslib helpers rather than inlining helpers for iteration or spreading, for instance
"importHelpers": true
},
"include": [
"src/**/*"
Expand Down
1 change: 1 addition & 0 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"styled-components": "3.3.3",
"tar-fs": "1.13.0",
"tinycolor2": "1.3.0",
"tslib": "^1.9.3",
"ui-select": "0.19.4",
"unbzip2-stream": "1.0.9",
"uuid": "3.0.1",
Expand Down
6 changes: 3 additions & 3 deletions x-pack/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7832,9 +7832,9 @@ trim-right@^1.0.1:
dependencies:
glob "^6.0.4"

tslib@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
tslib@^1.9.0, tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

tunnel-agent@^0.6.0:
version "0.6.0"
Expand Down
10 changes: 3 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13230,13 +13230,9 @@ ts-node@^7.0.1:
source-map-support "^0.5.6"
yn "^2.0.0"

tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1:
version "1.9.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.1.tgz#a5d1f0532a49221c87755cfcc89ca37197242ba7"

tslib@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"

tslint-config-prettier@^1.15.0:
version "1.15.0"
Expand Down

0 comments on commit b55705e

Please sign in to comment.