From 58055c822fd487063d4cfc80b87a7d9ff12cbcf8 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Fri, 7 Apr 2017 14:24:42 -0500 Subject: [PATCH 1/2] Support target versions as strings (#231) --- README.md | 4 +- data/built-ins.json | 1362 +++++++++-------- data/plugins.json | 367 ++--- package.json | 3 +- scripts/build-data.js | 12 +- src/index.js | 109 +- src/targets-parser.js | 133 ++ src/utils.js | 67 + test/debug-fixtures/android/stdout.txt | 218 +-- .../debug-fixtures/builtins-uglify/stdout.txt | 14 +- test/debug-fixtures/builtins/stdout.txt | 222 +-- test/debug-fixtures/electron/stdout.txt | 122 +- test/debug-fixtures/plugins-only/options.json | 3 +- test/debug-fixtures/plugins-only/stdout.txt | 21 +- .../specific-targets/stdout.txt | 228 +-- .../versions-decimals/options.json | 13 + .../versions-decimals/stdout.txt | 45 + .../versions-strings/options.json | 12 + .../versions-strings/stdout.txt | 36 + .../preset-options/electron/options.json | 2 +- .../preset-options/no-transform/options.json | 2 +- .../use-builtins-node-web/options.json | 4 +- .../use-builtins-node/options.json | 2 +- .../use-builtins-require/options.json | 2 +- test/index.spec.js | 160 +- test/targets-parser.spec.js | 117 ++ test/utils.spec.js | 61 + yarn.lock | 58 +- 28 files changed, 1864 insertions(+), 1535 deletions(-) create mode 100644 src/targets-parser.js create mode 100644 src/utils.js create mode 100644 test/debug-fixtures/versions-decimals/options.json create mode 100644 test/debug-fixtures/versions-decimals/stdout.txt create mode 100644 test/debug-fixtures/versions-strings/options.json create mode 100644 test/debug-fixtures/versions-strings/stdout.txt create mode 100644 test/targets-parser.spec.js create mode 100644 test/utils.spec.js diff --git a/README.md b/README.md index b3d9e01f..c3e8bc7b 100644 --- a/README.md +++ b/README.md @@ -98,11 +98,11 @@ For more information on setting options for a preset, refer to the [plugin/prese ### `targets` -`{ [string]: number }`, defaults to `{}`. +`{ [string]: number | string }`, defaults to `{}`. Takes an object of environment versions to support. -Each target environment takes a number (you can also specify a minor versions like `node: 6.5`) +Each target environment takes a number or a string (we recommend using a string when specifying minor versions like `node: "6.10"`). Example environments: `chrome`, `opera`, `edge`, `firefox`, `safari`, `ie`, `ios`, `android`, `node`, `electron`. diff --git a/data/built-ins.json b/data/built-ins.json index de589f66..dd478aab 100644 --- a/data/built-ins.json +++ b/data/built-ins.json @@ -1,848 +1,850 @@ { "es6.typed.array-buffer": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.data-view": { - "chrome": 5, - "opera": 12, - "edge": 12, - "firefox": 15, - "safari": 5.1, - "node": 0.12, - "ie": 10, - "android": 4, - "ios": 6, - "electron": 0.2 + "chrome": "5", + "opera": "12", + "edge": "12", + "firefox": "15", + "safari": "5.1", + "node": "0.12", + "ie": "10", + "android": "4", + "ios": "6", + "electron": "1.1" }, "es6.typed.int8-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.uint8-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.uint8-clamped-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.int16-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.uint16-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.int32-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.uint32-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.float32-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.typed.float64-array": { - "chrome": 51, - "edge": 13, - "firefox": 48, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "48", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.map": { - "chrome": 51, - "edge": 15, - "firefox": 53, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "15", + "firefox": "53", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.set": { - "chrome": 51, - "edge": 15, - "firefox": 53, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "15", + "firefox": "53", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.weak-map": { - "chrome": 51, - "edge": 15, - "firefox": 53, - "safari": 9, - "node": 6.5, - "ios": 9, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "15", + "firefox": "53", + "safari": "9", + "node": "6.5", + "ios": "9", + "opera": "38", + "electron": "1.2" }, "es6.weak-set": { - "chrome": 51, - "edge": 15, - "firefox": 53, - "safari": 9, - "node": 6.5, - "ios": 9, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "15", + "firefox": "53", + "safari": "9", + "node": "6.5", + "ios": "9", + "opera": "38", + "electron": "1.2" }, "es6.reflect.apply": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.construct": { - "chrome": 49, - "edge": 13, - "firefox": 45, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "13", + "firefox": "45", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.define-property": { - "chrome": 49, - "edge": 13, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "13", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.delete-property": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.get": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.get-own-property-descriptor": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.get-prototype-of": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.has": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.is-extensible": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.own-keys": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.prevent-extensions": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.set": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.reflect.set-prototype-of": { - "chrome": 49, - "edge": 12, - "firefox": 42, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "12", + "firefox": "42", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "es6.promise": { - "chrome": 51, - "edge": 13, - "firefox": 45, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "13", + "firefox": "45", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.symbol": { - "chrome": 51, - "firefox": 51, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "firefox": "51", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.object.assign": { - "chrome": 45, - "edge": 12, - "firefox": 34, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 32, - "electron": 0.35 + "chrome": "45", + "edge": "12", + "firefox": "34", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "32", + "electron": "0.35" }, "es6.object.is": { - "chrome": 19, - "edge": 12, - "firefox": 22, - "safari": 9, - "node": 0.12, - "android": 4.1, - "ios": 9, - "electron": 0.2 + "chrome": "19", + "edge": "12", + "firefox": "22", + "safari": "9", + "node": "0.12", + "android": "4.1", + "ios": "9", + "electron": "0.2" }, "es6.object.set-prototype-of": { - "chrome": 34, - "edge": 12, - "firefox": 31, - "safari": 9, - "node": 0.12, - "ie": 11, - "android": 5, - "ios": 9, - "opera": 21, - "electron": 0.2 + "chrome": "34", + "edge": "12", + "firefox": "31", + "safari": "9", + "node": "0.12", + "ie": "11", + "android": "5", + "ios": "9", + "opera": "21", + "electron": "0.2" }, "es6.function.name": { - "chrome": 51, - "firefox": 53, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "firefox": "53", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.string.raw": { - "chrome": 41, - "edge": 12, - "firefox": 34, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "12", + "firefox": "34", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "28", + "electron": "0.24" }, "es6.string.from-code-point": { - "chrome": 41, - "edge": 12, - "firefox": 29, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "12", + "firefox": "29", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "28", + "electron": "0.24" }, "es6.string.code-point-at": { - "chrome": 41, - "edge": 12, - "firefox": 29, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "12", + "firefox": "29", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "28", + "electron": "0.24" }, "es6.string.repeat": { - "chrome": 41, - "edge": 12, - "firefox": 24, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "12", + "firefox": "24", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "28", + "electron": "0.24" }, "es6.string.starts-with": { - "chrome": 41, - "edge": 12, - "firefox": 29, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "12", + "firefox": "29", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "28", + "electron": "0.24" }, "es6.string.ends-with": { - "chrome": 41, - "edge": 12, - "firefox": 29, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "12", + "firefox": "29", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "28", + "electron": "0.24" }, "es6.string.includes": { - "chrome": 41, - "edge": 12, - "firefox": 40, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "12", + "firefox": "40", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "28", + "electron": "0.24" }, "es6.regexp.flags": { - "chrome": 49, - "firefox": 37, - "safari": 9, - "node": 6, - "ios": 9, - "opera": 36, - "electron": 1 + "chrome": "49", + "firefox": "37", + "safari": "9", + "node": "6", + "ios": "9", + "opera": "36", + "electron": "1" }, "es6.regexp.match": { - "chrome": 50, - "firefox": 49, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 37, - "electron": 1.1 + "chrome": "50", + "firefox": "49", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "37", + "electron": "1.1" }, "es6.regexp.replace": { - "chrome": 50, - "firefox": 49, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 37, - "electron": 1.1 + "chrome": "50", + "firefox": "49", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "37", + "electron": "1.1" }, "es6.regexp.split": { - "chrome": 50, - "firefox": 49, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 37, - "electron": 1.1 + "chrome": "50", + "firefox": "49", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "37", + "electron": "1.1" }, "es6.regexp.search": { - "chrome": 50, - "firefox": 49, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 37, - "electron": 1.1 + "chrome": "50", + "firefox": "49", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "37", + "electron": "1.1" }, "es6.array.from": { - "chrome": 51, - "edge": 15, - "firefox": 36, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "15", + "firefox": "36", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "es6.array.of": { - "chrome": 45, - "edge": 12, - "firefox": 25, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 32, - "electron": 0.35 + "chrome": "45", + "edge": "12", + "firefox": "25", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "32", + "electron": "0.35" }, "es6.array.copy-within": { - "chrome": 45, - "edge": 12, - "firefox": 32, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 32, - "electron": 0.35 + "chrome": "45", + "edge": "12", + "firefox": "32", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "32", + "electron": "0.35" }, "es6.array.find": { - "chrome": 45, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 4, - "ios": 8, - "opera": 32, - "electron": 0.35 + "chrome": "45", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "4", + "ios": "8", + "opera": "32", + "electron": "0.35" }, "es6.array.find-index": { - "chrome": 45, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 4, - "ios": 8, - "opera": 32, - "electron": 0.35 + "chrome": "45", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "4", + "ios": "8", + "opera": "32", + "electron": "0.35" }, "es6.array.fill": { - "chrome": 45, - "edge": 12, - "firefox": 31, - "safari": 7.1, - "node": 4, - "ios": 8, - "opera": 32, - "electron": 0.35 + "chrome": "45", + "edge": "12", + "firefox": "31", + "safari": "7.1", + "node": "4", + "ios": "8", + "opera": "32", + "electron": "0.35" }, "es6.array.iterator": { - "chrome": 38, - "edge": 12, - "firefox": 28, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "28", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.number.is-finite": { - "chrome": 19, - "edge": 12, - "firefox": 16, - "safari": 9, - "node": 0.12, - "android": 4.1, - "ios": 9, - "electron": 0.2 + "chrome": "19", + "edge": "12", + "firefox": "16", + "safari": "9", + "node": "0.12", + "android": "4.1", + "ios": "9", + "electron": "0.2" }, "es6.number.is-integer": { - "chrome": 34, - "edge": 12, - "firefox": 16, - "safari": 9, - "node": 0.12, - "android": 5, - "ios": 9, - "opera": 21, - "electron": 0.2 + "chrome": "34", + "edge": "12", + "firefox": "16", + "safari": "9", + "node": "0.12", + "android": "5", + "ios": "9", + "opera": "21", + "electron": "0.2" }, "es6.number.is-safe-integer": { - "chrome": 34, - "edge": 12, - "firefox": 32, - "safari": 9, - "node": 0.12, - "android": 5, - "ios": 9, - "opera": 21, - "electron": 0.2 + "chrome": "34", + "edge": "12", + "firefox": "32", + "safari": "9", + "node": "0.12", + "android": "5", + "ios": "9", + "opera": "21", + "electron": "0.2" }, "es6.number.is-nan": { - "chrome": 19, - "edge": 12, - "firefox": 15, - "safari": 9, - "node": 0.12, - "android": 4.1, - "ios": 9, - "electron": 0.2 + "chrome": "19", + "edge": "12", + "firefox": "15", + "safari": "9", + "node": "0.12", + "android": "4.1", + "ios": "9", + "electron": "0.2" }, "es6.number.epsilon": { - "chrome": 34, - "edge": 12, - "firefox": 25, - "safari": 9, - "node": 0.12, - "android": 5, - "ios": 9, - "opera": 21, - "electron": 0.2 + "chrome": "34", + "edge": "12", + "firefox": "25", + "safari": "9", + "node": "0.12", + "android": "5", + "ios": "9", + "opera": "21", + "electron": "0.2" }, "es6.number.min-safe-integer": { - "chrome": 34, - "edge": 12, - "firefox": 31, - "safari": 9, - "node": 0.12, - "android": 5, - "ios": 9, - "opera": 21, - "electron": 0.2 + "chrome": "34", + "edge": "12", + "firefox": "31", + "safari": "9", + "node": "0.12", + "android": "5", + "ios": "9", + "opera": "21", + "electron": "0.2" }, "es6.number.max-safe-integer": { - "chrome": 34, - "edge": 12, - "firefox": 31, - "safari": 9, - "node": 0.12, - "android": 5, - "ios": 9, - "opera": 21, - "electron": 0.2 + "chrome": "34", + "edge": "12", + "firefox": "31", + "safari": "9", + "node": "0.12", + "android": "5", + "ios": "9", + "opera": "21", + "electron": "0.2" }, "es6.math.acosh": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.asinh": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.atanh": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.cbrt": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.clz32": { - "chrome": 38, - "edge": 12, - "firefox": 31, - "safari": 9, - "node": 0.12, - "android": 5.1, - "ios": 9, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "31", + "safari": "9", + "node": "0.12", + "android": "5.1", + "ios": "9", + "opera": "25", + "electron": "0.2" }, "es6.math.cosh": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.expm1": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.fround": { - "chrome": 38, - "edge": 12, - "firefox": 26, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "26", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.hypot": { - "chrome": 38, - "edge": 12, - "firefox": 27, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "27", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.imul": { - "chrome": 30, - "edge": 12, - "firefox": 23, - "safari": 7, - "node": 0.12, - "android": 4.4, - "ios": 7, - "opera": 17, - "electron": 0.2 + "chrome": "30", + "edge": "12", + "firefox": "23", + "safari": "7", + "node": "0.12", + "android": "4.4", + "ios": "7", + "opera": "17", + "electron": "0.2" }, "es6.math.log1p": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.log10": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.log2": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.sign": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 9, - "node": 0.12, - "android": 5.1, - "ios": 9, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "9", + "node": "0.12", + "android": "5.1", + "ios": "9", + "opera": "25", + "electron": "0.2" }, "es6.math.sinh": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.tanh": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es6.math.trunc": { - "chrome": 38, - "edge": 12, - "firefox": 25, - "safari": 7.1, - "node": 0.12, - "android": 5.1, - "ios": 8, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "25", + "safari": "7.1", + "node": "0.12", + "android": "5.1", + "ios": "8", + "opera": "25", + "electron": "0.2" }, "es7.array.includes": { - "chrome": 47, - "edge": 14, - "firefox": 43, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 34, - "electron": 0.36 + "chrome": "47", + "edge": "14", + "firefox": "43", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "34", + "electron": "0.36" }, "es7.object.values": { - "chrome": 54, - "edge": 14, - "firefox": 47, - "safari": 10.1, - "node": 7, - "ios": 10.3, - "opera": 41, - "electron": 1.5 + "chrome": "54", + "edge": "14", + "firefox": "47", + "safari": "10.1", + "node": "7", + "ios": "10.3", + "opera": "41", + "electron": "1.5" }, "es7.object.entries": { - "chrome": 54, - "edge": 14, - "firefox": 47, - "safari": 10.1, - "node": 7, - "ios": 10.3, - "opera": 41, - "electron": 1.5 + "chrome": "54", + "edge": "14", + "firefox": "47", + "safari": "10.1", + "node": "7", + "ios": "10.3", + "opera": "41", + "electron": "1.5" }, "es7.object.get-own-property-descriptors": { - "chrome": 54, - "edge": 15, - "firefox": 50, - "safari": 10.1, - "node": 7, - "ios": 10.3, - "opera": 41, - "electron": 1.5 + "chrome": "54", + "edge": "15", + "firefox": "50", + "safari": "10.1", + "node": "7", + "ios": "10.3", + "opera": "41", + "electron": "1.5" }, "es7.string.pad-start": { - "chrome": 57, - "edge": 15, - "firefox": 48, - "safari": 10, - "ios": 10, - "opera": 44 + "chrome": "57", + "edge": "15", + "firefox": "48", + "safari": "10", + "ios": "10", + "opera": "44", + "electron": "1.7" }, "es7.string.pad-end": { - "chrome": 57, - "edge": 15, - "firefox": 48, - "safari": 10, - "ios": 10, - "opera": 44 + "chrome": "57", + "edge": "15", + "firefox": "48", + "safari": "10", + "ios": "10", + "opera": "44", + "electron": "1.7" } } diff --git a/data/plugins.json b/data/plugins.json index ef9456b9..bca57cae 100644 --- a/data/plugins.json +++ b/data/plugins.json @@ -1,231 +1,232 @@ { "check-es2015-constants": { - "chrome": 49, - "edge": 14, - "firefox": 51, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "14", + "firefox": "51", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "transform-es2015-arrow-functions": { - "chrome": 47, - "edge": 13, - "firefox": 45, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 34, - "electron": 0.36 + "chrome": "47", + "edge": "13", + "firefox": "45", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "34", + "electron": "0.36" }, "transform-es2015-block-scoped-functions": { - "chrome": 41, - "edge": 12, - "firefox": 46, - "safari": 10, - "node": 4, - "ie": 11, - "ios": 10, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "12", + "firefox": "46", + "safari": "10", + "node": "4", + "ie": "11", + "ios": "10", + "opera": "28", + "electron": "0.24" }, "transform-es2015-block-scoping": { - "chrome": 49, - "edge": 14, - "firefox": 51, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "14", + "firefox": "51", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "transform-es2015-classes": { - "chrome": 46, - "edge": 13, - "firefox": 45, - "safari": 10, - "node": 5, - "ios": 10, - "opera": 33, - "electron": 0.36 + "chrome": "46", + "edge": "13", + "firefox": "45", + "safari": "10", + "node": "5", + "ios": "10", + "opera": "33", + "electron": "0.36" }, "transform-es2015-computed-properties": { - "chrome": 44, - "edge": 12, - "firefox": 34, - "safari": 7.1, - "node": 4, - "ios": 8, - "opera": 31, - "electron": 0.31 + "chrome": "44", + "edge": "12", + "firefox": "34", + "safari": "7.1", + "node": "4", + "ios": "8", + "opera": "31", + "electron": "0.31" }, "transform-es2015-destructuring": { - "chrome": 51, - "edge": 15, - "firefox": 53, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "15", + "firefox": "53", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "transform-es2015-duplicate-keys": { - "chrome": 42, - "edge": 12, - "firefox": 34, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 29, - "electron": 0.27 + "chrome": "42", + "edge": "12", + "firefox": "34", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "29", + "electron": "0.27" }, "transform-es2015-for-of": { - "chrome": 51, - "edge": 15, - "firefox": 53, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "edge": "15", + "firefox": "53", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "transform-es2015-function-name": { - "chrome": 51, - "firefox": 53, - "safari": 10, - "node": 6.5, - "ios": 10, - "opera": 38, - "electron": 1.2 + "chrome": "51", + "firefox": "53", + "safari": "10", + "node": "6.5", + "ios": "10", + "opera": "38", + "electron": "1.2" }, "transform-es2015-literals": { - "chrome": 44, - "edge": 12, - "firefox": 53, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 31, - "electron": 0.31 + "chrome": "44", + "edge": "12", + "firefox": "53", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "31", + "electron": "0.31" }, "transform-es2015-object-super": { - "chrome": 46, - "edge": 13, - "firefox": 45, - "safari": 10, - "node": 5, - "ios": 10, - "opera": 33, - "electron": 0.36 + "chrome": "46", + "edge": "13", + "firefox": "45", + "safari": "10", + "node": "5", + "ios": "10", + "opera": "33", + "electron": "0.36" }, "transform-es2015-parameters": { - "chrome": 49, - "edge": 14, - "firefox": 53, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "14", + "firefox": "53", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "transform-es2015-shorthand-properties": { - "chrome": 43, - "edge": 12, - "firefox": 33, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 30, - "electron": 0.29 + "chrome": "43", + "edge": "12", + "firefox": "33", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "30", + "electron": "0.29" }, "transform-es2015-spread": { - "chrome": 46, - "edge": 13, - "firefox": 36, - "safari": 10, - "node": 5, - "ios": 10, - "opera": 33, - "electron": 0.36 + "chrome": "46", + "edge": "13", + "firefox": "36", + "safari": "10", + "node": "5", + "ios": "10", + "opera": "33", + "electron": "0.36" }, "transform-es2015-sticky-regex": { - "chrome": 49, - "edge": 13, - "firefox": 3, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 36, - "electron": 1 + "chrome": "49", + "edge": "13", + "firefox": "3", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "36", + "electron": "1" }, "transform-es2015-template-literals": { - "chrome": 41, - "edge": 13, - "firefox": 34, - "safari": 9, - "node": 4, - "ios": 9, - "opera": 28, - "electron": 0.24 + "chrome": "41", + "edge": "13", + "firefox": "34", + "safari": "9", + "node": "4", + "ios": "9", + "opera": "28", + "electron": "0.24" }, "transform-es2015-typeof-symbol": { - "chrome": 38, - "edge": 12, - "firefox": 36, - "safari": 9, - "node": 0.12, - "android": 5.1, - "ios": 9, - "opera": 25, - "electron": 0.2 + "chrome": "38", + "edge": "12", + "firefox": "36", + "safari": "9", + "node": "0.12", + "android": "5.1", + "ios": "9", + "opera": "25", + "electron": "0.2" }, "transform-es2015-unicode-regex": { - "chrome": 50, - "edge": 13, - "firefox": 46, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 37, - "electron": 1.1 + "chrome": "50", + "edge": "13", + "firefox": "46", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "37", + "electron": "1.1" }, "transform-regenerator": { - "chrome": 50, - "edge": 13, - "firefox": 53, - "safari": 10, - "node": 6, - "ios": 10, - "opera": 37, - "electron": 1.1 + "chrome": "50", + "edge": "13", + "firefox": "53", + "safari": "10", + "node": "6", + "ios": "10", + "opera": "37", + "electron": "1.1" }, "transform-exponentiation-operator": { - "chrome": 52, - "edge": 14, - "firefox": 52, - "safari": 10.1, - "node": 7, - "ios": 10.3, - "opera": 39, - "electron": 1.3 + "chrome": "52", + "edge": "14", + "firefox": "52", + "safari": "10.1", + "node": "7", + "ios": "10.3", + "opera": "39", + "electron": "1.3" }, "transform-async-to-generator": { - "chrome": 55, - "edge": 15, - "firefox": 52, - "safari": 10.1, - "node": 7.6, - "ios": 10.3, - "opera": 42, - "electron": 1.6 + "chrome": "55", + "edge": "15", + "firefox": "52", + "safari": "10.1", + "node": "7.6", + "ios": "10.3", + "opera": "42", + "electron": "1.6" }, "syntax-trailing-function-commas": { - "chrome": 58, - "edge": 14, - "firefox": 52, - "safari": 10, - "ios": 10, - "opera": 45 + "chrome": "58", + "edge": "14", + "firefox": "52", + "safari": "10", + "ios": "10", + "opera": "45", + "electron": "1.7" } } diff --git a/package.json b/package.json index 72dc6611..9821e5f6 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ "babel-plugin-transform-exponentiation-operator": "^6.22.0", "babel-plugin-transform-regenerator": "^6.22.0", "browserslist": "^2.1.2", - "invariant": "^2.2.2" + "invariant": "^2.2.2", + "semver": "^5.3.0" }, "devDependencies": { "babel-cli": "^6.23.0", diff --git a/scripts/build-data.js b/scripts/build-data.js index 94ce128d..4f4be72c 100644 --- a/scripts/build-data.js +++ b/scripts/build-data.js @@ -211,20 +211,22 @@ const generateData = (environments, features) => { environments.forEach((env) => { const version = getLowestImplementedVersion(options, env); if (version !== null) { - plugin[env] = version; + plugin[env] = version.toString(); } }); - // add opera if (plugin.chrome) { + // add opera if (plugin.chrome >= 28) { - plugin.opera = plugin.chrome - 13; + plugin.opera = (plugin.chrome - 13).toString(); } else if (plugin.chrome === 5) { - plugin.opera = 12; + plugin.opera = "12"; } + + // add electron const electronVersion = chromiumToElectron(plugin.chrome); if (electronVersion) { - plugin.electron = electronVersion; + plugin.electron = electronVersion.toString(); } } diff --git a/src/index.js b/src/index.js index fe68ea23..b827a766 100644 --- a/src/index.js +++ b/src/index.js @@ -1,24 +1,25 @@ -import browserslist from "browserslist"; +import semver from "semver"; import builtInsList from "../data/built-ins.json"; import { defaultWebIncludes } from "./default-includes"; import moduleTransformations from "./module-transformations"; import normalizeOptions from "./normalize-options.js"; import pluginList from "../data/plugins.json"; import transformPolyfillRequirePlugin from "./transform-polyfill-require-plugin"; +import getTargets from "./targets-parser"; +import { _extends, prettifyTargets, prettifyVersion, semverify } from "./utils"; /** * Determine if a transformation is required + * + * NOTE: This assumes `supportedEnvironments` has already been parsed by `getTargets` + * * @param {Object} supportedEnvironments An Object containing environment keys and the lowest * supported version as a value * @param {Object} plugin An Object containing environment keys and the lowest * version the feature was implemented in as a value - * @return {Boolean} Whether or not the transformation is required + * @return {Boolean} Whether or not the transformation is required */ export const isPluginRequired = (supportedEnvironments, plugin) => { - if (supportedEnvironments.browsers) { - supportedEnvironments = getTargets(supportedEnvironments); - } - const targetEnvironments = Object.keys(supportedEnvironments); if (targetEnvironments.length === 0) { return true; } @@ -31,90 +32,20 @@ export const isPluginRequired = (supportedEnvironments, plugin) => { const lowestImplementedVersion = plugin[environment]; const lowestTargetedVersion = supportedEnvironments[environment]; - if (typeof lowestTargetedVersion === "string") { - throw new Error(`Target version must be a number, - '${lowestTargetedVersion}' was given for '${environment}'`); + if (!semver.valid(lowestTargetedVersion)) { + throw new Error( + // eslint-disable-next-line max-len + `Invalid version passed for target "${environment}": "${lowestTargetedVersion}". Versions must be in semver format (major.minor.patch)`, + ); } - return lowestTargetedVersion < lowestImplementedVersion; + return semver.gt( + semverify(lowestImplementedVersion), + lowestTargetedVersion, + ); }); - return isRequiredForEnvironments.length > 0 ? true : false; -}; - -const isBrowsersQueryValid = (browsers) => { - return typeof browsers === "string" || Array.isArray(browsers); -}; - -const browserNameMap = { - android: "android", - chrome: "chrome", - edge: "edge", - firefox: "firefox", - ie: "ie", - ios_saf: "ios", - safari: "safari" -}; - -const getLowestVersions = (browsers) => { - return browsers.reduce((all, browser) => { - const [browserName, browserVersion] = browser.split(" "); - const normalizedBrowserName = browserNameMap[browserName]; - const parsedBrowserVersion = parseInt(browserVersion); - if (normalizedBrowserName && !isNaN(parsedBrowserVersion)) { - all[normalizedBrowserName] = Math.min(all[normalizedBrowserName] || Infinity, parsedBrowserVersion); - } - return all; - }, {}); -}; - -const mergeBrowsers = (fromQuery, fromTarget) => { - return Object.keys(fromTarget).reduce((queryObj, targKey) => { - if (targKey !== "browsers") { - queryObj[targKey] = fromTarget[targKey]; - } - return queryObj; - }, fromQuery); -}; - -export const getCurrentNodeVersion = () => { - return parseFloat(process.versions.node); -}; - -const _extends = Object.assign || function (target) { - for (let i = 1; i < arguments.length; i++) { - const source = arguments[i]; - for (const key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } - } - return target; -}; - - -export const getTargets = (targets = {}) => { - const targetOpts = _extends({}, targets); - - if (targetOpts.node === true || targetOpts.node === "current") { - targetOpts.node = getCurrentNodeVersion(); - } - - if (typeof targetOpts.electron === "string") { - targetOpts.electron = parseFloat(targetOpts.electron); - } - - if (targetOpts.hasOwnProperty("uglify") && !targetOpts.uglify) { - delete targetOpts.uglify; - } - - const browserOpts = targetOpts.browsers; - if (isBrowsersQueryValid(browserOpts)) { - const queryBrowsers = getLowestVersions(browserslist(browserOpts)); - return mergeBrowsers(queryBrowsers, targetOpts); - } - return targetOpts; + return isRequiredForEnvironments.length > 0; }; let hasBeenLogged = false; @@ -123,8 +54,8 @@ const logPlugin = (plugin, targets, list) => { const envList = list[plugin] || {}; const filteredList = Object.keys(targets) .reduce((a, b) => { - if (!envList[b] || targets[b] < envList[b]) { - a[b] = targets[b]; + if (!envList[b] || semver.lt(targets[b], semverify(envList[b]))) { + a[b] = prettifyVersion(targets[b]); } return a; }, {}); @@ -191,7 +122,7 @@ export default function buildPreset(context, opts = {}) { hasBeenLogged = true; console.log("babel-preset-env: `DEBUG` option"); console.log("\nUsing targets:"); - console.log(JSON.stringify(targets, null, 2)); + console.log(JSON.stringify(prettifyTargets(targets), null, 2)); console.log(`\nModules transform: ${moduleType}`); console.log("\nUsing plugins:"); transformations.forEach((transform) => { diff --git a/src/targets-parser.js b/src/targets-parser.js new file mode 100644 index 00000000..3a1096a1 --- /dev/null +++ b/src/targets-parser.js @@ -0,0 +1,133 @@ +import browserslist from "browserslist"; +import semver from "semver"; +import { semverify } from "./utils"; + +const browserNameMap = { + android: "android", + chrome: "chrome", + edge: "edge", + firefox: "firefox", + ie: "ie", + ios_saf: "ios", + safari: "safari", +}; + +const isBrowsersQueryValid = (browsers) => + typeof browsers === "string" || Array.isArray(browsers); + +const semverMin = (first, second) => { + return first && semver.lt(first, second) ? first : second; +}; + +const getLowestVersions = (browsers) => { + return browsers.reduce( + (all, browser) => { + const [browserName, browserVersion] = browser.split(" "); + const normalizedBrowserName = browserNameMap[browserName]; + + if (!normalizedBrowserName) { + return all; + } + + try { + // Browser version can return as "10.0-10.2" + const splitVersion = browserVersion.split("-")[0]; + const parsedBrowserVersion = semverify(splitVersion); + + all[normalizedBrowserName] = semverMin( + all[normalizedBrowserName], + parsedBrowserVersion, + ); + } catch (e) {} + + return all; + }, + {}, + ); +}; + +const outputDecimalWarning = (decimalTargets) => { + if (!decimalTargets || !decimalTargets.length) { + return; + } + + console.log("Warning, the following targets are using a decimal version:"); + console.log(""); + decimalTargets.forEach(({ target, value }) => + console.log(` ${target}: ${value}`)); + console.log(""); + console.log( + "We recommend using a string for minor/patch versions to avoid numbers like 6.10", + ); + console.log("getting parsed as 6.1, which can lead to unexpected behavior."); + console.log(""); +}; + +const targetParserMap = { + __default: (target, value) => [target, semverify(value)], + + // Parse `node: true` and `node: "current"` to version + node: (target, value) => { + const parsed = value === true || value === "current" + ? process.versions.node + : semverify(value); + + return [target, parsed]; + }, + + // Only valid value for Uglify is `true` + uglify: (target, value) => [target, value === true], +}; + +const getTargets = (targets = {}) => { + let targetOpts = {}; + + // Parse browsers target via browserslist + if (isBrowsersQueryValid(targets.browsers)) { + targetOpts = getLowestVersions(browserslist(targets.browsers)); + } + + // Parse remaining targets + const parsed = Object.keys(targets).reduce( + (results, target) => { + if (target !== "browsers") { + const value = targets[target]; + + // Warn when specifying minor/patch as a decimal + if (typeof value === "number" && value % 1 !== 0) { + results.decimalWarnings.push({ target, value }); + } + + // Check if we have a target parser? + const parser = targetParserMap[target] || targetParserMap.__default; + const [parsedTarget, parsedValue] = parser(target, value); + + if (parsedValue) { + // Merge (lowest wins) + if (typeof parsedValue === "string") { + results.targets[parsedTarget] = semverMin( + results.targets[parsedTarget], + parsedValue, + ); + } else { + // We can remove this block if/when we replace Uglify target + // with top level option + results.targets[parsedTarget] = parsedValue; + } + } + } + + return results; + }, + { + targets: targetOpts, + decimalWarnings: [], + }, + ); + + outputDecimalWarning(parsed.decimalWarnings); + + return parsed.targets; +}; + +export default getTargets; diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 00000000..561d74f2 --- /dev/null +++ b/src/utils.js @@ -0,0 +1,67 @@ +// @flow +import semver from "semver"; + +export const _extends = Object.assign || + function(target) { + for (let i = 1; i < arguments.length; i++) { + const source = arguments[i]; + for (const key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; + }; + +// Convert version to a semver value. +// 2.5 -> 2.5.0; 1 -> 1.0.0; +export const semverify = (version) => { + if (typeof version === "string" && semver.valid(version)) { + return version; + } + + const split = version.toString().split("."); + + while (split.length < 3) { + split.push(0); + } + + return split.join("."); +}; + +export const prettifyVersion = (version) => { + if (typeof version !== "string") { + return version; + } + + const parts = [semver.major(version)]; + const minor = semver.minor(version); + const patch = semver.patch(version); + + if (minor || patch) { + parts.push(minor); + } + + if (patch) { + parts.push(patch); + } + + return parts.join("."); +}; + +export const prettifyTargets = (targets = {}) => { + return Object.keys(targets).reduce( + (results, target) => { + let value = targets[target]; + + if (typeof value === "string") { + value = prettifyVersion(value); + } + + results[target] = value; + return results; + }, + {}, + ); +}; diff --git a/test/debug-fixtures/android/stdout.txt b/test/debug-fixtures/android/stdout.txt index 3e792956..4c41227a 100644 --- a/test/debug-fixtures/android/stdout.txt +++ b/test/debug-fixtures/android/stdout.txt @@ -2,120 +2,120 @@ babel-preset-env: `DEBUG` option Using targets: { - "android": 4 + "android": "4" } Modules transform: commonjs Using plugins: - check-es2015-constants {"android":4} - transform-es2015-arrow-functions {"android":4} - transform-es2015-block-scoped-functions {"android":4} - transform-es2015-block-scoping {"android":4} - transform-es2015-classes {"android":4} - transform-es2015-computed-properties {"android":4} - transform-es2015-destructuring {"android":4} - transform-es2015-duplicate-keys {"android":4} - transform-es2015-for-of {"android":4} - transform-es2015-function-name {"android":4} - transform-es2015-literals {"android":4} - transform-es2015-object-super {"android":4} - transform-es2015-parameters {"android":4} - transform-es2015-shorthand-properties {"android":4} - transform-es2015-spread {"android":4} - transform-es2015-sticky-regex {"android":4} - transform-es2015-template-literals {"android":4} - transform-es2015-typeof-symbol {"android":4} - transform-es2015-unicode-regex {"android":4} - transform-regenerator {"android":4} - transform-exponentiation-operator {"android":4} - transform-async-to-generator {"android":4} - syntax-trailing-function-commas {"android":4} + check-es2015-constants {"android":"4"} + transform-es2015-arrow-functions {"android":"4"} + transform-es2015-block-scoped-functions {"android":"4"} + transform-es2015-block-scoping {"android":"4"} + transform-es2015-classes {"android":"4"} + transform-es2015-computed-properties {"android":"4"} + transform-es2015-destructuring {"android":"4"} + transform-es2015-duplicate-keys {"android":"4"} + transform-es2015-for-of {"android":"4"} + transform-es2015-function-name {"android":"4"} + transform-es2015-literals {"android":"4"} + transform-es2015-object-super {"android":"4"} + transform-es2015-parameters {"android":"4"} + transform-es2015-shorthand-properties {"android":"4"} + transform-es2015-spread {"android":"4"} + transform-es2015-sticky-regex {"android":"4"} + transform-es2015-template-literals {"android":"4"} + transform-es2015-typeof-symbol {"android":"4"} + transform-es2015-unicode-regex {"android":"4"} + transform-regenerator {"android":"4"} + transform-exponentiation-operator {"android":"4"} + transform-async-to-generator {"android":"4"} + syntax-trailing-function-commas {"android":"4"} Using polyfills: - es6.typed.array-buffer {"android":4} - es6.typed.int8-array {"android":4} - es6.typed.uint8-array {"android":4} - es6.typed.uint8-clamped-array {"android":4} - es6.typed.int16-array {"android":4} - es6.typed.uint16-array {"android":4} - es6.typed.int32-array {"android":4} - es6.typed.uint32-array {"android":4} - es6.typed.float32-array {"android":4} - es6.typed.float64-array {"android":4} - es6.map {"android":4} - es6.set {"android":4} - es6.weak-map {"android":4} - es6.weak-set {"android":4} - es6.reflect.apply {"android":4} - es6.reflect.construct {"android":4} - es6.reflect.define-property {"android":4} - es6.reflect.delete-property {"android":4} - es6.reflect.get {"android":4} - es6.reflect.get-own-property-descriptor {"android":4} - es6.reflect.get-prototype-of {"android":4} - es6.reflect.has {"android":4} - es6.reflect.is-extensible {"android":4} - es6.reflect.own-keys {"android":4} - es6.reflect.prevent-extensions {"android":4} - es6.reflect.set {"android":4} - es6.reflect.set-prototype-of {"android":4} - es6.promise {"android":4} - es6.symbol {"android":4} - es6.object.assign {"android":4} - es6.object.is {"android":4} - es6.object.set-prototype-of {"android":4} - es6.function.name {"android":4} - es6.string.raw {"android":4} - es6.string.from-code-point {"android":4} - es6.string.code-point-at {"android":4} - es6.string.repeat {"android":4} - es6.string.starts-with {"android":4} - es6.string.ends-with {"android":4} - es6.string.includes {"android":4} - es6.regexp.flags {"android":4} - es6.regexp.match {"android":4} - es6.regexp.replace {"android":4} - es6.regexp.split {"android":4} - es6.regexp.search {"android":4} - es6.array.from {"android":4} - es6.array.of {"android":4} - es6.array.copy-within {"android":4} - es6.array.find {"android":4} - es6.array.find-index {"android":4} - es6.array.fill {"android":4} - es6.array.iterator {"android":4} - es6.number.is-finite {"android":4} - es6.number.is-integer {"android":4} - es6.number.is-safe-integer {"android":4} - es6.number.is-nan {"android":4} - es6.number.epsilon {"android":4} - es6.number.min-safe-integer {"android":4} - es6.number.max-safe-integer {"android":4} - es6.math.acosh {"android":4} - es6.math.asinh {"android":4} - es6.math.atanh {"android":4} - es6.math.cbrt {"android":4} - es6.math.clz32 {"android":4} - es6.math.cosh {"android":4} - es6.math.expm1 {"android":4} - es6.math.fround {"android":4} - es6.math.hypot {"android":4} - es6.math.imul {"android":4} - es6.math.log1p {"android":4} - es6.math.log10 {"android":4} - es6.math.log2 {"android":4} - es6.math.sign {"android":4} - es6.math.sinh {"android":4} - es6.math.tanh {"android":4} - es6.math.trunc {"android":4} - es7.array.includes {"android":4} - es7.object.values {"android":4} - es7.object.entries {"android":4} - es7.object.get-own-property-descriptors {"android":4} - es7.string.pad-start {"android":4} - es7.string.pad-end {"android":4} - web.timers {"android":4} - web.immediate {"android":4} - web.dom.iterable {"android":4} + es6.typed.array-buffer {"android":"4"} + es6.typed.int8-array {"android":"4"} + es6.typed.uint8-array {"android":"4"} + es6.typed.uint8-clamped-array {"android":"4"} + es6.typed.int16-array {"android":"4"} + es6.typed.uint16-array {"android":"4"} + es6.typed.int32-array {"android":"4"} + es6.typed.uint32-array {"android":"4"} + es6.typed.float32-array {"android":"4"} + es6.typed.float64-array {"android":"4"} + es6.map {"android":"4"} + es6.set {"android":"4"} + es6.weak-map {"android":"4"} + es6.weak-set {"android":"4"} + es6.reflect.apply {"android":"4"} + es6.reflect.construct {"android":"4"} + es6.reflect.define-property {"android":"4"} + es6.reflect.delete-property {"android":"4"} + es6.reflect.get {"android":"4"} + es6.reflect.get-own-property-descriptor {"android":"4"} + es6.reflect.get-prototype-of {"android":"4"} + es6.reflect.has {"android":"4"} + es6.reflect.is-extensible {"android":"4"} + es6.reflect.own-keys {"android":"4"} + es6.reflect.prevent-extensions {"android":"4"} + es6.reflect.set {"android":"4"} + es6.reflect.set-prototype-of {"android":"4"} + es6.promise {"android":"4"} + es6.symbol {"android":"4"} + es6.object.assign {"android":"4"} + es6.object.is {"android":"4"} + es6.object.set-prototype-of {"android":"4"} + es6.function.name {"android":"4"} + es6.string.raw {"android":"4"} + es6.string.from-code-point {"android":"4"} + es6.string.code-point-at {"android":"4"} + es6.string.repeat {"android":"4"} + es6.string.starts-with {"android":"4"} + es6.string.ends-with {"android":"4"} + es6.string.includes {"android":"4"} + es6.regexp.flags {"android":"4"} + es6.regexp.match {"android":"4"} + es6.regexp.replace {"android":"4"} + es6.regexp.split {"android":"4"} + es6.regexp.search {"android":"4"} + es6.array.from {"android":"4"} + es6.array.of {"android":"4"} + es6.array.copy-within {"android":"4"} + es6.array.find {"android":"4"} + es6.array.find-index {"android":"4"} + es6.array.fill {"android":"4"} + es6.array.iterator {"android":"4"} + es6.number.is-finite {"android":"4"} + es6.number.is-integer {"android":"4"} + es6.number.is-safe-integer {"android":"4"} + es6.number.is-nan {"android":"4"} + es6.number.epsilon {"android":"4"} + es6.number.min-safe-integer {"android":"4"} + es6.number.max-safe-integer {"android":"4"} + es6.math.acosh {"android":"4"} + es6.math.asinh {"android":"4"} + es6.math.atanh {"android":"4"} + es6.math.cbrt {"android":"4"} + es6.math.clz32 {"android":"4"} + es6.math.cosh {"android":"4"} + es6.math.expm1 {"android":"4"} + es6.math.fround {"android":"4"} + es6.math.hypot {"android":"4"} + es6.math.imul {"android":"4"} + es6.math.log1p {"android":"4"} + es6.math.log10 {"android":"4"} + es6.math.log2 {"android":"4"} + es6.math.sign {"android":"4"} + es6.math.sinh {"android":"4"} + es6.math.tanh {"android":"4"} + es6.math.trunc {"android":"4"} + es7.array.includes {"android":"4"} + es7.object.values {"android":"4"} + es7.object.entries {"android":"4"} + es7.object.get-own-property-descriptors {"android":"4"} + es7.string.pad-start {"android":"4"} + es7.string.pad-end {"android":"4"} + web.timers {"android":"4"} + web.immediate {"android":"4"} + web.dom.iterable {"android":"4"} src/in.js -> lib/in.js \ No newline at end of file diff --git a/test/debug-fixtures/builtins-uglify/stdout.txt b/test/debug-fixtures/builtins-uglify/stdout.txt index 44f3707b..42973232 100644 --- a/test/debug-fixtures/builtins-uglify/stdout.txt +++ b/test/debug-fixtures/builtins-uglify/stdout.txt @@ -2,7 +2,7 @@ babel-preset-env: `DEBUG` option Using targets: { - "chrome": 55, + "chrome": "55", "uglify": true } @@ -31,12 +31,12 @@ Using plugins: transform-regenerator {"uglify":true} transform-exponentiation-operator {"uglify":true} transform-async-to-generator {"uglify":true} - syntax-trailing-function-commas {"chrome":55,"uglify":true} + syntax-trailing-function-commas {"chrome":"55","uglify":true} Using polyfills: - es7.string.pad-start {"chrome":55} - es7.string.pad-end {"chrome":55} - web.timers {"chrome":55} - web.immediate {"chrome":55} - web.dom.iterable {"chrome":55} + es7.string.pad-start {"chrome":"55"} + es7.string.pad-end {"chrome":"55"} + web.timers {"chrome":"55"} + web.immediate {"chrome":"55"} + web.dom.iterable {"chrome":"55"} src/in.js -> lib/in.js \ No newline at end of file diff --git a/test/debug-fixtures/builtins/stdout.txt b/test/debug-fixtures/builtins/stdout.txt index 1779d879..97ffb883 100644 --- a/test/debug-fixtures/builtins/stdout.txt +++ b/test/debug-fixtures/builtins/stdout.txt @@ -2,122 +2,122 @@ babel-preset-env: `DEBUG` option Using targets: { - "chrome": 54, - "ie": 10, - "node": 6 + "chrome": "54", + "ie": "10", + "node": "6" } Modules transform: commonjs Using plugins: - check-es2015-constants {"ie":10} - transform-es2015-arrow-functions {"ie":10} - transform-es2015-block-scoped-functions {"ie":10} - transform-es2015-block-scoping {"ie":10} - transform-es2015-classes {"ie":10} - transform-es2015-computed-properties {"ie":10} - transform-es2015-destructuring {"ie":10,"node":6} - transform-es2015-duplicate-keys {"ie":10} - transform-es2015-for-of {"ie":10,"node":6} - transform-es2015-function-name {"ie":10,"node":6} - transform-es2015-literals {"ie":10} - transform-es2015-object-super {"ie":10} - transform-es2015-parameters {"ie":10} - transform-es2015-shorthand-properties {"ie":10} - transform-es2015-spread {"ie":10} - transform-es2015-sticky-regex {"ie":10} - transform-es2015-template-literals {"ie":10} - transform-es2015-typeof-symbol {"ie":10} - transform-es2015-unicode-regex {"ie":10} - transform-regenerator {"ie":10} - transform-exponentiation-operator {"ie":10,"node":6} - transform-async-to-generator {"chrome":54,"ie":10,"node":6} - syntax-trailing-function-commas {"chrome":54,"ie":10,"node":6} + check-es2015-constants {"ie":"10"} + transform-es2015-arrow-functions {"ie":"10"} + transform-es2015-block-scoped-functions {"ie":"10"} + transform-es2015-block-scoping {"ie":"10"} + transform-es2015-classes {"ie":"10"} + transform-es2015-computed-properties {"ie":"10"} + transform-es2015-destructuring {"ie":"10","node":"6"} + transform-es2015-duplicate-keys {"ie":"10"} + transform-es2015-for-of {"ie":"10","node":"6"} + transform-es2015-function-name {"ie":"10","node":"6"} + transform-es2015-literals {"ie":"10"} + transform-es2015-object-super {"ie":"10"} + transform-es2015-parameters {"ie":"10"} + transform-es2015-shorthand-properties {"ie":"10"} + transform-es2015-spread {"ie":"10"} + transform-es2015-sticky-regex {"ie":"10"} + transform-es2015-template-literals {"ie":"10"} + transform-es2015-typeof-symbol {"ie":"10"} + transform-es2015-unicode-regex {"ie":"10"} + transform-regenerator {"ie":"10"} + transform-exponentiation-operator {"ie":"10","node":"6"} + transform-async-to-generator {"chrome":"54","ie":"10","node":"6"} + syntax-trailing-function-commas {"chrome":"54","ie":"10","node":"6"} Using polyfills: - es6.typed.array-buffer {"ie":10,"node":6} - es6.typed.int8-array {"ie":10,"node":6} - es6.typed.uint8-array {"ie":10,"node":6} - es6.typed.uint8-clamped-array {"ie":10,"node":6} - es6.typed.int16-array {"ie":10,"node":6} - es6.typed.uint16-array {"ie":10,"node":6} - es6.typed.int32-array {"ie":10,"node":6} - es6.typed.uint32-array {"ie":10,"node":6} - es6.typed.float32-array {"ie":10,"node":6} - es6.typed.float64-array {"ie":10,"node":6} - es6.map {"ie":10,"node":6} - es6.set {"ie":10,"node":6} - es6.weak-map {"ie":10,"node":6} - es6.weak-set {"ie":10,"node":6} - es6.reflect.apply {"ie":10} - es6.reflect.construct {"ie":10} - es6.reflect.define-property {"ie":10} - es6.reflect.delete-property {"ie":10} - es6.reflect.get {"ie":10} - es6.reflect.get-own-property-descriptor {"ie":10} - es6.reflect.get-prototype-of {"ie":10} - es6.reflect.has {"ie":10} - es6.reflect.is-extensible {"ie":10} - es6.reflect.own-keys {"ie":10} - es6.reflect.prevent-extensions {"ie":10} - es6.reflect.set {"ie":10} - es6.reflect.set-prototype-of {"ie":10} - es6.promise {"ie":10,"node":6} - es6.symbol {"ie":10,"node":6} - es6.object.assign {"ie":10} - es6.object.is {"ie":10} - es6.object.set-prototype-of {"ie":10} - es6.function.name {"ie":10,"node":6} - es6.string.raw {"ie":10} - es6.string.from-code-point {"ie":10} - es6.string.code-point-at {"ie":10} - es6.string.repeat {"ie":10} - es6.string.starts-with {"ie":10} - es6.string.ends-with {"ie":10} - es6.string.includes {"ie":10} - es6.regexp.flags {"ie":10} - es6.regexp.match {"ie":10} - es6.regexp.replace {"ie":10} - es6.regexp.split {"ie":10} - es6.regexp.search {"ie":10} - es6.array.from {"ie":10,"node":6} - es6.array.of {"ie":10} - es6.array.copy-within {"ie":10} - es6.array.find {"ie":10} - es6.array.find-index {"ie":10} - es6.array.fill {"ie":10} - es6.array.iterator {"ie":10} - es6.number.is-finite {"ie":10} - es6.number.is-integer {"ie":10} - es6.number.is-safe-integer {"ie":10} - es6.number.is-nan {"ie":10} - es6.number.epsilon {"ie":10} - es6.number.min-safe-integer {"ie":10} - es6.number.max-safe-integer {"ie":10} - es6.math.acosh {"ie":10} - es6.math.asinh {"ie":10} - es6.math.atanh {"ie":10} - es6.math.cbrt {"ie":10} - es6.math.clz32 {"ie":10} - es6.math.cosh {"ie":10} - es6.math.expm1 {"ie":10} - es6.math.fround {"ie":10} - es6.math.hypot {"ie":10} - es6.math.imul {"ie":10} - es6.math.log1p {"ie":10} - es6.math.log10 {"ie":10} - es6.math.log2 {"ie":10} - es6.math.sign {"ie":10} - es6.math.sinh {"ie":10} - es6.math.tanh {"ie":10} - es6.math.trunc {"ie":10} - es7.array.includes {"ie":10} - es7.object.values {"ie":10,"node":6} - es7.object.entries {"ie":10,"node":6} - es7.object.get-own-property-descriptors {"ie":10,"node":6} - es7.string.pad-start {"chrome":54,"ie":10,"node":6} - es7.string.pad-end {"chrome":54,"ie":10,"node":6} - web.timers {"chrome":54,"ie":10,"node":6} - web.immediate {"chrome":54,"ie":10,"node":6} - web.dom.iterable {"chrome":54,"ie":10,"node":6} + es6.typed.array-buffer {"ie":"10","node":"6"} + es6.typed.int8-array {"ie":"10","node":"6"} + es6.typed.uint8-array {"ie":"10","node":"6"} + es6.typed.uint8-clamped-array {"ie":"10","node":"6"} + es6.typed.int16-array {"ie":"10","node":"6"} + es6.typed.uint16-array {"ie":"10","node":"6"} + es6.typed.int32-array {"ie":"10","node":"6"} + es6.typed.uint32-array {"ie":"10","node":"6"} + es6.typed.float32-array {"ie":"10","node":"6"} + es6.typed.float64-array {"ie":"10","node":"6"} + es6.map {"ie":"10","node":"6"} + es6.set {"ie":"10","node":"6"} + es6.weak-map {"ie":"10","node":"6"} + es6.weak-set {"ie":"10","node":"6"} + es6.reflect.apply {"ie":"10"} + es6.reflect.construct {"ie":"10"} + es6.reflect.define-property {"ie":"10"} + es6.reflect.delete-property {"ie":"10"} + es6.reflect.get {"ie":"10"} + es6.reflect.get-own-property-descriptor {"ie":"10"} + es6.reflect.get-prototype-of {"ie":"10"} + es6.reflect.has {"ie":"10"} + es6.reflect.is-extensible {"ie":"10"} + es6.reflect.own-keys {"ie":"10"} + es6.reflect.prevent-extensions {"ie":"10"} + es6.reflect.set {"ie":"10"} + es6.reflect.set-prototype-of {"ie":"10"} + es6.promise {"ie":"10","node":"6"} + es6.symbol {"ie":"10","node":"6"} + es6.object.assign {"ie":"10"} + es6.object.is {"ie":"10"} + es6.object.set-prototype-of {"ie":"10"} + es6.function.name {"ie":"10","node":"6"} + es6.string.raw {"ie":"10"} + es6.string.from-code-point {"ie":"10"} + es6.string.code-point-at {"ie":"10"} + es6.string.repeat {"ie":"10"} + es6.string.starts-with {"ie":"10"} + es6.string.ends-with {"ie":"10"} + es6.string.includes {"ie":"10"} + es6.regexp.flags {"ie":"10"} + es6.regexp.match {"ie":"10"} + es6.regexp.replace {"ie":"10"} + es6.regexp.split {"ie":"10"} + es6.regexp.search {"ie":"10"} + es6.array.from {"ie":"10","node":"6"} + es6.array.of {"ie":"10"} + es6.array.copy-within {"ie":"10"} + es6.array.find {"ie":"10"} + es6.array.find-index {"ie":"10"} + es6.array.fill {"ie":"10"} + es6.array.iterator {"ie":"10"} + es6.number.is-finite {"ie":"10"} + es6.number.is-integer {"ie":"10"} + es6.number.is-safe-integer {"ie":"10"} + es6.number.is-nan {"ie":"10"} + es6.number.epsilon {"ie":"10"} + es6.number.min-safe-integer {"ie":"10"} + es6.number.max-safe-integer {"ie":"10"} + es6.math.acosh {"ie":"10"} + es6.math.asinh {"ie":"10"} + es6.math.atanh {"ie":"10"} + es6.math.cbrt {"ie":"10"} + es6.math.clz32 {"ie":"10"} + es6.math.cosh {"ie":"10"} + es6.math.expm1 {"ie":"10"} + es6.math.fround {"ie":"10"} + es6.math.hypot {"ie":"10"} + es6.math.imul {"ie":"10"} + es6.math.log1p {"ie":"10"} + es6.math.log10 {"ie":"10"} + es6.math.log2 {"ie":"10"} + es6.math.sign {"ie":"10"} + es6.math.sinh {"ie":"10"} + es6.math.tanh {"ie":"10"} + es6.math.trunc {"ie":"10"} + es7.array.includes {"ie":"10"} + es7.object.values {"ie":"10","node":"6"} + es7.object.entries {"ie":"10","node":"6"} + es7.object.get-own-property-descriptors {"ie":"10","node":"6"} + es7.string.pad-start {"chrome":"54","ie":"10","node":"6"} + es7.string.pad-end {"chrome":"54","ie":"10","node":"6"} + web.timers {"chrome":"54","ie":"10","node":"6"} + web.immediate {"chrome":"54","ie":"10","node":"6"} + web.dom.iterable {"chrome":"54","ie":"10","node":"6"} src/in.js -> lib/in.js \ No newline at end of file diff --git a/test/debug-fixtures/electron/stdout.txt b/test/debug-fixtures/electron/stdout.txt index c1128e45..1d3da440 100644 --- a/test/debug-fixtures/electron/stdout.txt +++ b/test/debug-fixtures/electron/stdout.txt @@ -1,69 +1,77 @@ +Warning, the following targets are using a decimal version: + + electron: 0.36 + +We recommend using a string for minor/patch versions to avoid numbers like 6.10 +getting parsed as 6.1, which can lead to unexpected behavior. + babel-preset-env: `DEBUG` option Using targets: { - "electron": 0.36 + "electron": "0.36" } Modules transform: commonjs Using plugins: - check-es2015-constants {"electron":0.36} - transform-es2015-block-scoping {"electron":0.36} - transform-es2015-destructuring {"electron":0.36} - transform-es2015-for-of {"electron":0.36} - transform-es2015-function-name {"electron":0.36} - transform-es2015-parameters {"electron":0.36} - transform-es2015-sticky-regex {"electron":0.36} - transform-es2015-unicode-regex {"electron":0.36} - transform-regenerator {"electron":0.36} - transform-exponentiation-operator {"electron":0.36} - transform-async-to-generator {"electron":0.36} - syntax-trailing-function-commas {"electron":0.36} + check-es2015-constants {"electron":"0.36"} + transform-es2015-block-scoping {"electron":"0.36"} + transform-es2015-destructuring {"electron":"0.36"} + transform-es2015-for-of {"electron":"0.36"} + transform-es2015-function-name {"electron":"0.36"} + transform-es2015-parameters {"electron":"0.36"} + transform-es2015-sticky-regex {"electron":"0.36"} + transform-es2015-unicode-regex {"electron":"0.36"} + transform-regenerator {"electron":"0.36"} + transform-exponentiation-operator {"electron":"0.36"} + transform-async-to-generator {"electron":"0.36"} + syntax-trailing-function-commas {"electron":"0.36"} Using polyfills: - es6.typed.array-buffer {"electron":0.36} - es6.typed.int8-array {"electron":0.36} - es6.typed.uint8-array {"electron":0.36} - es6.typed.uint8-clamped-array {"electron":0.36} - es6.typed.int16-array {"electron":0.36} - es6.typed.uint16-array {"electron":0.36} - es6.typed.int32-array {"electron":0.36} - es6.typed.uint32-array {"electron":0.36} - es6.typed.float32-array {"electron":0.36} - es6.typed.float64-array {"electron":0.36} - es6.map {"electron":0.36} - es6.set {"electron":0.36} - es6.weak-map {"electron":0.36} - es6.weak-set {"electron":0.36} - es6.reflect.apply {"electron":0.36} - es6.reflect.construct {"electron":0.36} - es6.reflect.define-property {"electron":0.36} - es6.reflect.delete-property {"electron":0.36} - es6.reflect.get {"electron":0.36} - es6.reflect.get-own-property-descriptor {"electron":0.36} - es6.reflect.get-prototype-of {"electron":0.36} - es6.reflect.has {"electron":0.36} - es6.reflect.is-extensible {"electron":0.36} - es6.reflect.own-keys {"electron":0.36} - es6.reflect.prevent-extensions {"electron":0.36} - es6.reflect.set {"electron":0.36} - es6.reflect.set-prototype-of {"electron":0.36} - es6.promise {"electron":0.36} - es6.symbol {"electron":0.36} - es6.function.name {"electron":0.36} - es6.regexp.flags {"electron":0.36} - es6.regexp.match {"electron":0.36} - es6.regexp.replace {"electron":0.36} - es6.regexp.split {"electron":0.36} - es6.regexp.search {"electron":0.36} - es6.array.from {"electron":0.36} - es7.object.values {"electron":0.36} - es7.object.entries {"electron":0.36} - es7.object.get-own-property-descriptors {"electron":0.36} - es7.string.pad-start {"electron":0.36} - es7.string.pad-end {"electron":0.36} - web.timers {"electron":0.36} - web.immediate {"electron":0.36} - web.dom.iterable {"electron":0.36} + es6.typed.array-buffer {"electron":"0.36"} + es6.typed.data-view {"electron":"0.36"} + es6.typed.int8-array {"electron":"0.36"} + es6.typed.uint8-array {"electron":"0.36"} + es6.typed.uint8-clamped-array {"electron":"0.36"} + es6.typed.int16-array {"electron":"0.36"} + es6.typed.uint16-array {"electron":"0.36"} + es6.typed.int32-array {"electron":"0.36"} + es6.typed.uint32-array {"electron":"0.36"} + es6.typed.float32-array {"electron":"0.36"} + es6.typed.float64-array {"electron":"0.36"} + es6.map {"electron":"0.36"} + es6.set {"electron":"0.36"} + es6.weak-map {"electron":"0.36"} + es6.weak-set {"electron":"0.36"} + es6.reflect.apply {"electron":"0.36"} + es6.reflect.construct {"electron":"0.36"} + es6.reflect.define-property {"electron":"0.36"} + es6.reflect.delete-property {"electron":"0.36"} + es6.reflect.get {"electron":"0.36"} + es6.reflect.get-own-property-descriptor {"electron":"0.36"} + es6.reflect.get-prototype-of {"electron":"0.36"} + es6.reflect.has {"electron":"0.36"} + es6.reflect.is-extensible {"electron":"0.36"} + es6.reflect.own-keys {"electron":"0.36"} + es6.reflect.prevent-extensions {"electron":"0.36"} + es6.reflect.set {"electron":"0.36"} + es6.reflect.set-prototype-of {"electron":"0.36"} + es6.promise {"electron":"0.36"} + es6.symbol {"electron":"0.36"} + es6.function.name {"electron":"0.36"} + es6.regexp.flags {"electron":"0.36"} + es6.regexp.match {"electron":"0.36"} + es6.regexp.replace {"electron":"0.36"} + es6.regexp.split {"electron":"0.36"} + es6.regexp.search {"electron":"0.36"} + es6.array.from {"electron":"0.36"} + es7.object.values {"electron":"0.36"} + es7.object.entries {"electron":"0.36"} + es7.object.get-own-property-descriptors {"electron":"0.36"} + es7.string.pad-start {"electron":"0.36"} + es7.string.pad-end {"electron":"0.36"} + web.timers {"electron":"0.36"} + web.immediate {"electron":"0.36"} + web.dom.iterable {"electron":"0.36"} src/in.js -> lib/in.js \ No newline at end of file diff --git a/test/debug-fixtures/plugins-only/options.json b/test/debug-fixtures/plugins-only/options.json index c04dc1ba..2b1d88bc 100644 --- a/test/debug-fixtures/plugins-only/options.json +++ b/test/debug-fixtures/plugins-only/options.json @@ -4,7 +4,8 @@ "debug": true, "exclude": [ "transform-async-to-generator", - "transform-regenerator", "transform-es2015-parameters" + "transform-regenerator", + "transform-es2015-parameters" ], "targets": { "firefox": 52, diff --git a/test/debug-fixtures/plugins-only/stdout.txt b/test/debug-fixtures/plugins-only/stdout.txt index a2ccd28b..d6672838 100644 --- a/test/debug-fixtures/plugins-only/stdout.txt +++ b/test/debug-fixtures/plugins-only/stdout.txt @@ -1,17 +1,24 @@ +Warning, the following targets are using a decimal version: + + node: 7.4 + +We recommend using a string for minor/patch versions to avoid numbers like 6.10 +getting parsed as 6.1, which can lead to unexpected behavior. + babel-preset-env: `DEBUG` option Using targets: { - "firefox": 52, - "node": 7.4 + "firefox": "52", + "node": "7.4" } Modules transform: commonjs Using plugins: - transform-es2015-destructuring {"firefox":52} - transform-es2015-for-of {"firefox":52} - transform-es2015-function-name {"firefox":52} - transform-es2015-literals {"firefox":52} - syntax-trailing-function-commas {"node":7.4} + transform-es2015-destructuring {"firefox":"52"} + transform-es2015-for-of {"firefox":"52"} + transform-es2015-function-name {"firefox":"52"} + transform-es2015-literals {"firefox":"52"} + syntax-trailing-function-commas {"node":"7.4"} src/in.js -> lib/in.js \ No newline at end of file diff --git a/test/debug-fixtures/specific-targets/stdout.txt b/test/debug-fixtures/specific-targets/stdout.txt index fe07366e..2fed2817 100644 --- a/test/debug-fixtures/specific-targets/stdout.txt +++ b/test/debug-fixtures/specific-targets/stdout.txt @@ -2,125 +2,125 @@ babel-preset-env: `DEBUG` option Using targets: { - "chrome": 54, - "edge": 13, - "firefox": 49, - "ie": 10, - "ios": 9, - "safari": 7 + "chrome": "54", + "edge": "13", + "firefox": "49", + "ie": "10", + "ios": "9", + "safari": "7" } Modules transform: commonjs Using plugins: - check-es2015-constants {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - transform-es2015-arrow-functions {"ie":10,"ios":9,"safari":7} - transform-es2015-block-scoped-functions {"ie":10,"ios":9,"safari":7} - transform-es2015-block-scoping {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - transform-es2015-classes {"ie":10,"ios":9,"safari":7} - transform-es2015-computed-properties {"ie":10,"safari":7} - transform-es2015-destructuring {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - transform-es2015-duplicate-keys {"ie":10,"safari":7} - transform-es2015-for-of {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - transform-es2015-function-name {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - transform-es2015-literals {"firefox":49,"ie":10,"safari":7} - transform-es2015-object-super {"ie":10,"ios":9,"safari":7} - transform-es2015-parameters {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - transform-es2015-shorthand-properties {"ie":10,"safari":7} - transform-es2015-spread {"ie":10,"ios":9,"safari":7} - transform-es2015-sticky-regex {"ie":10,"ios":9,"safari":7} - transform-es2015-template-literals {"ie":10,"safari":7} - transform-es2015-typeof-symbol {"ie":10,"safari":7} - transform-es2015-unicode-regex {"ie":10,"ios":9,"safari":7} - transform-regenerator {"firefox":49,"ie":10,"ios":9,"safari":7} - transform-exponentiation-operator {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - transform-async-to-generator {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - syntax-trailing-function-commas {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} + check-es2015-constants {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + transform-es2015-arrow-functions {"ie":"10","ios":"9","safari":"7"} + transform-es2015-block-scoped-functions {"ie":"10","ios":"9","safari":"7"} + transform-es2015-block-scoping {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + transform-es2015-classes {"ie":"10","ios":"9","safari":"7"} + transform-es2015-computed-properties {"ie":"10","safari":"7"} + transform-es2015-destructuring {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + transform-es2015-duplicate-keys {"ie":"10","safari":"7"} + transform-es2015-for-of {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + transform-es2015-function-name {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + transform-es2015-literals {"firefox":"49","ie":"10","safari":"7"} + transform-es2015-object-super {"ie":"10","ios":"9","safari":"7"} + transform-es2015-parameters {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + transform-es2015-shorthand-properties {"ie":"10","safari":"7"} + transform-es2015-spread {"ie":"10","ios":"9","safari":"7"} + transform-es2015-sticky-regex {"ie":"10","ios":"9","safari":"7"} + transform-es2015-template-literals {"ie":"10","safari":"7"} + transform-es2015-typeof-symbol {"ie":"10","safari":"7"} + transform-es2015-unicode-regex {"ie":"10","ios":"9","safari":"7"} + transform-regenerator {"firefox":"49","ie":"10","ios":"9","safari":"7"} + transform-exponentiation-operator {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + transform-async-to-generator {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + syntax-trailing-function-commas {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} Using polyfills: - es6.typed.array-buffer {"ie":10,"ios":9,"safari":7} - es6.typed.int8-array {"ie":10,"ios":9,"safari":7} - es6.typed.uint8-array {"ie":10,"ios":9,"safari":7} - es6.typed.uint8-clamped-array {"ie":10,"ios":9,"safari":7} - es6.typed.int16-array {"ie":10,"ios":9,"safari":7} - es6.typed.uint16-array {"ie":10,"ios":9,"safari":7} - es6.typed.int32-array {"ie":10,"ios":9,"safari":7} - es6.typed.uint32-array {"ie":10,"ios":9,"safari":7} - es6.typed.float32-array {"ie":10,"ios":9,"safari":7} - es6.typed.float64-array {"ie":10,"ios":9,"safari":7} - es6.map {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - es6.set {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - es6.weak-map {"edge":13,"firefox":49,"ie":10,"safari":7} - es6.weak-set {"edge":13,"firefox":49,"ie":10,"safari":7} - es6.reflect.apply {"ie":10,"ios":9,"safari":7} - es6.reflect.construct {"ie":10,"ios":9,"safari":7} - es6.reflect.define-property {"ie":10,"ios":9,"safari":7} - es6.reflect.delete-property {"ie":10,"ios":9,"safari":7} - es6.reflect.get {"ie":10,"ios":9,"safari":7} - es6.reflect.get-own-property-descriptor {"ie":10,"ios":9,"safari":7} - es6.reflect.get-prototype-of {"ie":10,"ios":9,"safari":7} - es6.reflect.has {"ie":10,"ios":9,"safari":7} - es6.reflect.is-extensible {"ie":10,"ios":9,"safari":7} - es6.reflect.own-keys {"ie":10,"ios":9,"safari":7} - es6.reflect.prevent-extensions {"ie":10,"ios":9,"safari":7} - es6.reflect.set {"ie":10,"ios":9,"safari":7} - es6.reflect.set-prototype-of {"ie":10,"ios":9,"safari":7} - es6.promise {"ie":10,"ios":9,"safari":7} - es6.symbol {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - es6.object.assign {"ie":10,"safari":7} - es6.object.is {"ie":10,"safari":7} - es6.object.set-prototype-of {"ie":10,"safari":7} - es6.function.name {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - es6.string.raw {"ie":10,"safari":7} - es6.string.from-code-point {"ie":10,"safari":7} - es6.string.code-point-at {"ie":10,"safari":7} - es6.string.repeat {"ie":10,"safari":7} - es6.string.starts-with {"ie":10,"safari":7} - es6.string.ends-with {"ie":10,"safari":7} - es6.string.includes {"ie":10,"safari":7} - es6.regexp.flags {"edge":13,"ie":10,"safari":7} - es6.regexp.match {"edge":13,"ie":10,"ios":9,"safari":7} - es6.regexp.replace {"edge":13,"ie":10,"ios":9,"safari":7} - es6.regexp.split {"edge":13,"ie":10,"ios":9,"safari":7} - es6.regexp.search {"edge":13,"ie":10,"ios":9,"safari":7} - es6.array.from {"edge":13,"ie":10,"ios":9,"safari":7} - es6.array.of {"ie":10,"safari":7} - es6.array.copy-within {"ie":10,"safari":7} - es6.array.find {"ie":10,"safari":7} - es6.array.find-index {"ie":10,"safari":7} - es6.array.fill {"ie":10,"safari":7} - es6.array.iterator {"ie":10,"safari":7} - es6.number.is-finite {"ie":10,"safari":7} - es6.number.is-integer {"ie":10,"safari":7} - es6.number.is-safe-integer {"ie":10,"safari":7} - es6.number.is-nan {"ie":10,"safari":7} - es6.number.epsilon {"ie":10,"safari":7} - es6.number.min-safe-integer {"ie":10,"safari":7} - es6.number.max-safe-integer {"ie":10,"safari":7} - es6.math.acosh {"ie":10,"safari":7} - es6.math.asinh {"ie":10,"safari":7} - es6.math.atanh {"ie":10,"safari":7} - es6.math.cbrt {"ie":10,"safari":7} - es6.math.clz32 {"ie":10,"safari":7} - es6.math.cosh {"ie":10,"safari":7} - es6.math.expm1 {"ie":10,"safari":7} - es6.math.fround {"ie":10,"safari":7} - es6.math.hypot {"ie":10,"safari":7} - es6.math.imul {"ie":10} - es6.math.log1p {"ie":10,"safari":7} - es6.math.log10 {"ie":10,"safari":7} - es6.math.log2 {"ie":10,"safari":7} - es6.math.sign {"ie":10,"safari":7} - es6.math.sinh {"ie":10,"safari":7} - es6.math.tanh {"ie":10,"safari":7} - es6.math.trunc {"ie":10,"safari":7} - es7.array.includes {"edge":13,"ie":10,"ios":9,"safari":7} - es7.object.values {"edge":13,"ie":10,"ios":9,"safari":7} - es7.object.entries {"edge":13,"ie":10,"ios":9,"safari":7} - es7.object.get-own-property-descriptors {"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - es7.string.pad-start {"chrome":54,"edge":13,"ie":10,"ios":9,"safari":7} - es7.string.pad-end {"chrome":54,"edge":13,"ie":10,"ios":9,"safari":7} - web.timers {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - web.immediate {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} - web.dom.iterable {"chrome":54,"edge":13,"firefox":49,"ie":10,"ios":9,"safari":7} + es6.typed.array-buffer {"ie":"10","ios":"9","safari":"7"} + es6.typed.int8-array {"ie":"10","ios":"9","safari":"7"} + es6.typed.uint8-array {"ie":"10","ios":"9","safari":"7"} + es6.typed.uint8-clamped-array {"ie":"10","ios":"9","safari":"7"} + es6.typed.int16-array {"ie":"10","ios":"9","safari":"7"} + es6.typed.uint16-array {"ie":"10","ios":"9","safari":"7"} + es6.typed.int32-array {"ie":"10","ios":"9","safari":"7"} + es6.typed.uint32-array {"ie":"10","ios":"9","safari":"7"} + es6.typed.float32-array {"ie":"10","ios":"9","safari":"7"} + es6.typed.float64-array {"ie":"10","ios":"9","safari":"7"} + es6.map {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + es6.set {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + es6.weak-map {"edge":"13","firefox":"49","ie":"10","safari":"7"} + es6.weak-set {"edge":"13","firefox":"49","ie":"10","safari":"7"} + es6.reflect.apply {"ie":"10","ios":"9","safari":"7"} + es6.reflect.construct {"ie":"10","ios":"9","safari":"7"} + es6.reflect.define-property {"ie":"10","ios":"9","safari":"7"} + es6.reflect.delete-property {"ie":"10","ios":"9","safari":"7"} + es6.reflect.get {"ie":"10","ios":"9","safari":"7"} + es6.reflect.get-own-property-descriptor {"ie":"10","ios":"9","safari":"7"} + es6.reflect.get-prototype-of {"ie":"10","ios":"9","safari":"7"} + es6.reflect.has {"ie":"10","ios":"9","safari":"7"} + es6.reflect.is-extensible {"ie":"10","ios":"9","safari":"7"} + es6.reflect.own-keys {"ie":"10","ios":"9","safari":"7"} + es6.reflect.prevent-extensions {"ie":"10","ios":"9","safari":"7"} + es6.reflect.set {"ie":"10","ios":"9","safari":"7"} + es6.reflect.set-prototype-of {"ie":"10","ios":"9","safari":"7"} + es6.promise {"ie":"10","ios":"9","safari":"7"} + es6.symbol {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + es6.object.assign {"ie":"10","safari":"7"} + es6.object.is {"ie":"10","safari":"7"} + es6.object.set-prototype-of {"ie":"10","safari":"7"} + es6.function.name {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + es6.string.raw {"ie":"10","safari":"7"} + es6.string.from-code-point {"ie":"10","safari":"7"} + es6.string.code-point-at {"ie":"10","safari":"7"} + es6.string.repeat {"ie":"10","safari":"7"} + es6.string.starts-with {"ie":"10","safari":"7"} + es6.string.ends-with {"ie":"10","safari":"7"} + es6.string.includes {"ie":"10","safari":"7"} + es6.regexp.flags {"edge":"13","ie":"10","safari":"7"} + es6.regexp.match {"edge":"13","ie":"10","ios":"9","safari":"7"} + es6.regexp.replace {"edge":"13","ie":"10","ios":"9","safari":"7"} + es6.regexp.split {"edge":"13","ie":"10","ios":"9","safari":"7"} + es6.regexp.search {"edge":"13","ie":"10","ios":"9","safari":"7"} + es6.array.from {"edge":"13","ie":"10","ios":"9","safari":"7"} + es6.array.of {"ie":"10","safari":"7"} + es6.array.copy-within {"ie":"10","safari":"7"} + es6.array.find {"ie":"10","safari":"7"} + es6.array.find-index {"ie":"10","safari":"7"} + es6.array.fill {"ie":"10","safari":"7"} + es6.array.iterator {"ie":"10","safari":"7"} + es6.number.is-finite {"ie":"10","safari":"7"} + es6.number.is-integer {"ie":"10","safari":"7"} + es6.number.is-safe-integer {"ie":"10","safari":"7"} + es6.number.is-nan {"ie":"10","safari":"7"} + es6.number.epsilon {"ie":"10","safari":"7"} + es6.number.min-safe-integer {"ie":"10","safari":"7"} + es6.number.max-safe-integer {"ie":"10","safari":"7"} + es6.math.acosh {"ie":"10","safari":"7"} + es6.math.asinh {"ie":"10","safari":"7"} + es6.math.atanh {"ie":"10","safari":"7"} + es6.math.cbrt {"ie":"10","safari":"7"} + es6.math.clz32 {"ie":"10","safari":"7"} + es6.math.cosh {"ie":"10","safari":"7"} + es6.math.expm1 {"ie":"10","safari":"7"} + es6.math.fround {"ie":"10","safari":"7"} + es6.math.hypot {"ie":"10","safari":"7"} + es6.math.imul {"ie":"10"} + es6.math.log1p {"ie":"10","safari":"7"} + es6.math.log10 {"ie":"10","safari":"7"} + es6.math.log2 {"ie":"10","safari":"7"} + es6.math.sign {"ie":"10","safari":"7"} + es6.math.sinh {"ie":"10","safari":"7"} + es6.math.tanh {"ie":"10","safari":"7"} + es6.math.trunc {"ie":"10","safari":"7"} + es7.array.includes {"edge":"13","ie":"10","ios":"9","safari":"7"} + es7.object.values {"edge":"13","ie":"10","ios":"9","safari":"7"} + es7.object.entries {"edge":"13","ie":"10","ios":"9","safari":"7"} + es7.object.get-own-property-descriptors {"edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + es7.string.pad-start {"chrome":"54","edge":"13","ie":"10","ios":"9","safari":"7"} + es7.string.pad-end {"chrome":"54","edge":"13","ie":"10","ios":"9","safari":"7"} + web.timers {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + web.immediate {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} + web.dom.iterable {"chrome":"54","edge":"13","firefox":"49","ie":"10","ios":"9","safari":"7"} src/in.js -> lib/in.js \ No newline at end of file diff --git a/test/debug-fixtures/versions-decimals/options.json b/test/debug-fixtures/versions-decimals/options.json new file mode 100644 index 00000000..451949b4 --- /dev/null +++ b/test/debug-fixtures/versions-decimals/options.json @@ -0,0 +1,13 @@ +{ + "presets": [ + ["../../lib", { + "debug": true, + "targets": { + "chrome": 54, + "electron": 0.36, + "node": 6.10, + "ie": 10 + } + }] + ] +} diff --git a/test/debug-fixtures/versions-decimals/stdout.txt b/test/debug-fixtures/versions-decimals/stdout.txt new file mode 100644 index 00000000..4fd7b712 --- /dev/null +++ b/test/debug-fixtures/versions-decimals/stdout.txt @@ -0,0 +1,45 @@ +Warning, the following targets are using a decimal version: + + electron: 0.36 + node: 6.1 + +We recommend using a string for minor/patch versions to avoid numbers like 6.10 +getting parsed as 6.1, which can lead to unexpected behavior. + +babel-preset-env: `DEBUG` option + +Using targets: +{ + "chrome": "54", + "electron": "0.36", + "node": "6.1", + "ie": "10" +} + +Modules transform: commonjs + +Using plugins: + check-es2015-constants {"electron":"0.36","ie":"10"} + transform-es2015-arrow-functions {"ie":"10"} + transform-es2015-block-scoped-functions {"ie":"10"} + transform-es2015-block-scoping {"electron":"0.36","ie":"10"} + transform-es2015-classes {"ie":"10"} + transform-es2015-computed-properties {"ie":"10"} + transform-es2015-destructuring {"electron":"0.36","node":"6.1","ie":"10"} + transform-es2015-duplicate-keys {"ie":"10"} + transform-es2015-for-of {"electron":"0.36","node":"6.1","ie":"10"} + transform-es2015-function-name {"electron":"0.36","node":"6.1","ie":"10"} + transform-es2015-literals {"ie":"10"} + transform-es2015-object-super {"ie":"10"} + transform-es2015-parameters {"electron":"0.36","ie":"10"} + transform-es2015-shorthand-properties {"ie":"10"} + transform-es2015-spread {"ie":"10"} + transform-es2015-sticky-regex {"electron":"0.36","ie":"10"} + transform-es2015-template-literals {"ie":"10"} + transform-es2015-typeof-symbol {"ie":"10"} + transform-es2015-unicode-regex {"electron":"0.36","ie":"10"} + transform-regenerator {"electron":"0.36","ie":"10"} + transform-exponentiation-operator {"electron":"0.36","node":"6.1","ie":"10"} + transform-async-to-generator {"chrome":"54","electron":"0.36","node":"6.1","ie":"10"} + syntax-trailing-function-commas {"chrome":"54","electron":"0.36","node":"6.1","ie":"10"} +src/in.js -> lib/in.js \ No newline at end of file diff --git a/test/debug-fixtures/versions-strings/options.json b/test/debug-fixtures/versions-strings/options.json new file mode 100644 index 00000000..0954a3ae --- /dev/null +++ b/test/debug-fixtures/versions-strings/options.json @@ -0,0 +1,12 @@ +{ + "presets": [ + ["../../lib", { + "debug": true, + "targets": { + "chrome": "54", + "node": "6.10", + "ie": "10" + } + }] + ] +} diff --git a/test/debug-fixtures/versions-strings/stdout.txt b/test/debug-fixtures/versions-strings/stdout.txt new file mode 100644 index 00000000..bd62d119 --- /dev/null +++ b/test/debug-fixtures/versions-strings/stdout.txt @@ -0,0 +1,36 @@ +babel-preset-env: `DEBUG` option + +Using targets: +{ + "chrome": "54", + "node": "6.10", + "ie": "10" +} + +Modules transform: commonjs + +Using plugins: + check-es2015-constants {"ie":"10"} + transform-es2015-arrow-functions {"ie":"10"} + transform-es2015-block-scoped-functions {"ie":"10"} + transform-es2015-block-scoping {"ie":"10"} + transform-es2015-classes {"ie":"10"} + transform-es2015-computed-properties {"ie":"10"} + transform-es2015-destructuring {"ie":"10"} + transform-es2015-duplicate-keys {"ie":"10"} + transform-es2015-for-of {"ie":"10"} + transform-es2015-function-name {"ie":"10"} + transform-es2015-literals {"ie":"10"} + transform-es2015-object-super {"ie":"10"} + transform-es2015-parameters {"ie":"10"} + transform-es2015-shorthand-properties {"ie":"10"} + transform-es2015-spread {"ie":"10"} + transform-es2015-sticky-regex {"ie":"10"} + transform-es2015-template-literals {"ie":"10"} + transform-es2015-typeof-symbol {"ie":"10"} + transform-es2015-unicode-regex {"ie":"10"} + transform-regenerator {"ie":"10"} + transform-exponentiation-operator {"node":"6.10","ie":"10"} + transform-async-to-generator {"chrome":"54","node":"6.10","ie":"10"} + syntax-trailing-function-commas {"chrome":"54","node":"6.10","ie":"10"} +src/in.js -> lib/in.js \ No newline at end of file diff --git a/test/fixtures/preset-options/electron/options.json b/test/fixtures/preset-options/electron/options.json index 281c0fd3..26135107 100644 --- a/test/fixtures/preset-options/electron/options.json +++ b/test/fixtures/preset-options/electron/options.json @@ -2,7 +2,7 @@ "presets": [ ["../../../../lib", { "targets": { - "electron": 1.4 + "electron": "1.4" }, "modules": false, "useBuiltIns": true diff --git a/test/fixtures/preset-options/no-transform/options.json b/test/fixtures/preset-options/no-transform/options.json index de09fa3f..c35fc697 100644 --- a/test/fixtures/preset-options/no-transform/options.json +++ b/test/fixtures/preset-options/no-transform/options.json @@ -2,7 +2,7 @@ "presets": [ ["../../../../lib", { "targets": { - "chrome": 55 + "chrome": "55" }, "modules": false, "useBuiltIns": true diff --git a/test/fixtures/preset-options/use-builtins-node-web/options.json b/test/fixtures/preset-options/use-builtins-node-web/options.json index 7d156cdc..aca3540b 100644 --- a/test/fixtures/preset-options/use-builtins-node-web/options.json +++ b/test/fixtures/preset-options/use-builtins-node-web/options.json @@ -2,8 +2,8 @@ "presets": [ ["../../../../lib", { "targets": { - "chrome": 55, - "node": 7.6, + "chrome": "55", + "node": "7.6", "uglify": true }, "modules": false, diff --git a/test/fixtures/preset-options/use-builtins-node/options.json b/test/fixtures/preset-options/use-builtins-node/options.json index cc2666d5..49ccb53f 100644 --- a/test/fixtures/preset-options/use-builtins-node/options.json +++ b/test/fixtures/preset-options/use-builtins-node/options.json @@ -2,7 +2,7 @@ "presets": [ ["../../../../lib", { "targets": { - "node": 7.6, + "node": "7.6", "uglify": true }, "modules": false, diff --git a/test/fixtures/preset-options/use-builtins-require/options.json b/test/fixtures/preset-options/use-builtins-require/options.json index de09fa3f..c35fc697 100644 --- a/test/fixtures/preset-options/use-builtins-require/options.json +++ b/test/fixtures/preset-options/use-builtins-require/options.json @@ -2,7 +2,7 @@ "presets": [ ["../../../../lib", { "targets": { - "chrome": 55 + "chrome": "55" }, "modules": false, "useBuiltIns": true diff --git a/test/index.spec.js b/test/index.spec.js index d71735a8..6eea95cc 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -4,56 +4,11 @@ const babelPresetEnv = require("../lib/index.js"); const assert = require("assert"); describe("babel-preset-env", () => { - describe("getTargets", () => { - it("should return the current node version with option 'current'", function() { - assert.deepEqual(babelPresetEnv.getTargets({ - node: true - }), { - node: parseFloat(process.versions.node) - }); - - assert.deepEqual(babelPresetEnv.getTargets({ - node: "current" - }), { - node: parseFloat(process.versions.node) - }); - }); - - it("transforms electron version to a number", function() { - assert.deepEqual(babelPresetEnv.getTargets({ - electron: "1.2" - }), { - electron: 1.2 - }); - }); - }); - - describe("getTargets + uglify", () => { - it("should work with `true`", function() { - assert.deepEqual(babelPresetEnv.getTargets({ - uglify: true - }), { - uglify: true - }); - }); - - it("should ignore `false`", function() { - assert.deepEqual(babelPresetEnv.getTargets({ - uglify: false - }), {}); - }); - - it("should ignore `null`", function() { - assert.deepEqual(babelPresetEnv.getTargets({ - uglify: null - }), {}); - }); - }); - describe("isPluginRequired", () => { + const MAX_VERSION = `${Number.MAX_SAFE_INTEGER}.0.0`; + it("returns true if no targets are specified", () => { - const isRequired = babelPresetEnv.isPluginRequired({}, {}); - assert(isRequired); + assert.strictEqual(babelPresetEnv.isPluginRequired({}, {}), true); }); it("returns true if plugin feature is not implemented in one or more targets", () => { @@ -65,15 +20,21 @@ describe("babel-preset-env", () => { }; targets = { - "chrome": Number.MAX_SAFE_INTEGER, - "firefox": Number.MAX_SAFE_INTEGER + chrome: MAX_VERSION, + firefox: MAX_VERSION, }; - assert(babelPresetEnv.isPluginRequired(targets, plugin) === false); + assert.strictEqual( + babelPresetEnv.isPluginRequired(targets, plugin), + false, + ); targets = { - "edge": 12, + edge: "12", }; - assert(babelPresetEnv.isPluginRequired(plugin, plugin) === true); + assert.strictEqual( + babelPresetEnv.isPluginRequired(targets, plugin), + true, + ); }); it("returns false if plugin feature is implemented by lower than target", () => { @@ -81,9 +42,13 @@ describe("babel-preset-env", () => { chrome: 49, }; const targets = { - "chrome": Number.MAX_SAFE_INTEGER, + chrome: MAX_VERSION, }; - assert(babelPresetEnv.isPluginRequired(targets, plugin) === false); + + assert.strictEqual( + babelPresetEnv.isPluginRequired(targets, plugin), + false, + ); }); it("returns false if plugin feature is implemented is equal to target", () => { @@ -91,9 +56,12 @@ describe("babel-preset-env", () => { chrome: 49, }; const targets = { - "chrome": 49, + chrome: "49.0.0", }; - assert(babelPresetEnv.isPluginRequired(targets, plugin) === false); + assert.strictEqual( + babelPresetEnv.isPluginRequired(targets, plugin), + false, + ); }); it("returns true if plugin feature is implemented is greater than target", () => { @@ -101,81 +69,49 @@ describe("babel-preset-env", () => { chrome: 50, }; const targets = { - "chrome": 49, - }; - assert(babelPresetEnv.isPluginRequired(targets, plugin) === true); - }); - - it("returns false if plugin feature is implemented by lower than target defined in browsers query", () => { - const plugin = { - chrome: 49, - }; - const targets = { - "browsers": "chrome > 50" + chrome: "49.0.0", }; - assert(babelPresetEnv.isPluginRequired(targets, plugin) === false); - }); - - it("returns true if plugin feature is implemented is greater than target defined in browsers query", () => { - const plugin = { - chrome: 52, - }; - const targets = { - "browsers": "chrome > 50" - }; - assert(babelPresetEnv.isPluginRequired(targets, plugin) === true); - }); - - it("returns true if target's root items overrides versions defined in browsers query", () => { - const plugin = { - chrome: 45, - }; - const targets = { - browsers: "last 2 Chrome versions", - chrome: 44 - }; - - assert(babelPresetEnv.isPluginRequired(targets, plugin) === true); + assert.strictEqual( + babelPresetEnv.isPluginRequired(targets, plugin), + true, + ); }); it("returns true if uglify is specified as a target", () => { const plugin = { - chrome: 50 + chrome: 50, }; const targets = { - chrome: 55, - uglify: true + chrome: "55.0.0", + uglify: true, }; - - assert(babelPresetEnv.isPluginRequired(targets, plugin) === true); + assert.strictEqual( + babelPresetEnv.isPluginRequired(targets, plugin), + true, + ); }); - it("doesn't throw when specifying a decimal for node", () => { + it("returns when target is a decimal", () => { const plugin = { - node: 6 + node: 6.9, }; - const targets = { - "node": 6.5 + node: "6.10.0", }; - - assert.doesNotThrow(() => { - babelPresetEnv.isPluginRequired(targets, plugin); - }, Error); + assert.strictEqual( + babelPresetEnv.isPluginRequired(targets, plugin), + false, + ); }); - it("will throw if target version is not a number", () => { + it("throws an error if target version is invalid", () => { const plugin = { - "node": 6, + chrome: 50, }; - const targets = { - "node": "6.5", + chrome: 55, }; - - assert.throws(() => { - babelPresetEnv.isPluginRequired(targets, plugin); - }, Error); + assert.throws(() => babelPresetEnv.isPluginRequired(targets, plugin)); }); }); diff --git a/test/targets-parser.spec.js b/test/targets-parser.spec.js new file mode 100644 index 00000000..ff569174 --- /dev/null +++ b/test/targets-parser.spec.js @@ -0,0 +1,117 @@ +import assert from "assert"; +import getTargets from "../src/targets-parser"; + +describe("getTargets", () => { + it("parses", () => { + assert.deepEqual( + getTargets({ + chrome: 49, + firefox: "55", + ie: "9", + node: "6.10", + electron: "1.6", + }), + { + chrome: "49.0.0", + electron: "1.6.0", + firefox: "55.0.0", + ie: "9.0.0", + node: "6.10.0", + }, + ); + }); + + describe("browser", () => { + it("merges browser key targets", () => { + assert.deepEqual( + getTargets({ + browsers: "chrome 56, ie 11, firefox 51, safari 9", + chrome: "49", + firefox: "55", + ie: "9", + }), + { + chrome: "49.0.0", + firefox: "51.0.0", + ie: "9.0.0", + safari: "9.0.0", + }, + ); + }); + + it("ignores invalid", () => { + assert.deepEqual( + getTargets({ + browsers: 59, + chrome: "49", + firefox: "55", + ie: "11", + }), + { + chrome: "49.0.0", + firefox: "55.0.0", + ie: "11.0.0", + }, + ); + }); + }); + + describe("node", () => { + it("should return the current node version with option 'current'", () => { + assert.deepEqual( + getTargets({ + node: true, + }), + { + node: process.versions.node, + }, + ); + }); + }); + + describe("electron", () => { + it("should be its own target", () => { + assert.deepEqual( + getTargets({ + chrome: "46", + electron: "0.34", + }), + { + chrome: "46.0.0", + electron: "0.34.0", + }, + ); + }); + }); + + describe("uglify", () => { + it("should work with `true`", function() { + assert.deepEqual( + getTargets({ + uglify: true, + }), + { + uglify: true, + }, + ); + }); + + it("should ignore `false`", function() { + assert.deepEqual( + getTargets({ + uglify: false, + }), + {}, + ); + }); + + it("should ignore `null`", function() { + assert.deepEqual( + getTargets({ + uglify: null, + }), + {}, + ); + }); + }); +}); diff --git a/test/utils.spec.js b/test/utils.spec.js new file mode 100644 index 00000000..d3bcd765 --- /dev/null +++ b/test/utils.spec.js @@ -0,0 +1,61 @@ +"use strict"; + +const utils = require("../lib/utils"); +const assert = require("assert"); + +const { + prettifyTargets, + prettifyVersion, + semverify, +} = utils; + +describe("utils", () => { + describe("semverify", () => { + it("returns", () => { + assert.strictEqual(semverify("1"), "1.0.0"); + assert.strictEqual(semverify("1.0"), "1.0.0"); + assert.strictEqual(semverify("1.0.0"), "1.0.0"); + assert.strictEqual(semverify(1), "1.0.0"); + assert.strictEqual(semverify(1.2), "1.2.0"); + }); + }); + + describe("prettifyVersion", () => { + it("returns", () => { + assert.strictEqual(prettifyVersion(true), true); + assert.strictEqual(prettifyVersion("0.16.0"), "0.16"); + assert.strictEqual(prettifyVersion("1.0.0"), "1"); + assert.strictEqual(prettifyVersion("1.1.0"), "1.1"); + assert.strictEqual(prettifyVersion("1.0.2"), "1.0.2"); + assert.strictEqual(prettifyVersion("1.2.3"), "1.2.3"); + }); + }); + + describe("prettifyTargets", () => { + it("returns", () => { + assert.deepEqual(prettifyTargets({}), {}); + + assert.deepEqual( + prettifyTargets({ + uglify: true, + }), + { + uglify: true, + }, + ); + + assert.deepEqual( + prettifyTargets({ + chrome: "54.0.0", + electron: "1.6.0", + node: "0.12.0", + }), + { + chrome: "54", + electron: "1.6", + node: "0.12", + }, + ); + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index 5e56c150..1fcd28cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,10 +22,6 @@ acorn-jsx@^3.0.0: dependencies: acorn "^3.0.4" -acorn@4.0.4, acorn@^4.0.3: - version "4.0.4" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.4.tgz#17a8d6a7a6c4ef538b814ec9abac2779293bf30a" - acorn@^2.1.0, acorn@^2.4.0: version "2.7.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-2.7.0.tgz#ab6e7d9d886aaca8b085bc3312b79a198433f0e7" @@ -34,6 +30,10 @@ acorn@^3.0.4: version "3.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" +acorn@^4.0.3: + version "4.0.4" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.4.tgz#17a8d6a7a6c4ef538b814ec9abac2779293bf30a" + acorn@^5.0.1: version "5.0.2" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.0.2.tgz#dc1c8fb907f64db2ab573de2326b73527c24de36" @@ -233,31 +233,7 @@ babel-code-frame@^6.22.0: esutils "^2.0.2" js-tokens "^3.0.0" -babel-core@^6.23.0: - version "6.23.1" - resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.23.1.tgz#c143cb621bb2f621710c220c5d579d15b8a442df" - dependencies: - babel-code-frame "^6.22.0" - babel-generator "^6.23.0" - babel-helpers "^6.23.0" - babel-messages "^6.23.0" - babel-register "^6.23.0" - babel-runtime "^6.22.0" - babel-template "^6.23.0" - babel-traverse "^6.23.1" - babel-types "^6.23.0" - babylon "^6.11.0" - convert-source-map "^1.1.0" - debug "^2.1.1" - json5 "^0.5.0" - lodash "^4.2.0" - minimatch "^3.0.2" - path-is-absolute "^1.0.0" - private "^0.1.6" - slash "^1.0.0" - source-map "^0.5.0" - -babel-core@^6.24.0, babel-core@latest: +babel-core@^6.23.0, babel-core@^6.24.0, babel-core@latest: version "6.24.0" resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.24.0.tgz#8f36a0a77f5c155aed6f920b844d23ba56742a02" dependencies: @@ -291,20 +267,7 @@ babel-eslint@^7.1.1: babylon "^6.13.0" lodash.pickby "^4.6.0" -babel-generator@^6.18.0, babel-generator@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.23.0.tgz#6b8edab956ef3116f79d8c84c5a3c05f32a74bc5" - dependencies: - babel-messages "^6.23.0" - babel-runtime "^6.22.0" - babel-types "^6.23.0" - detect-indent "^4.0.0" - jsesc "^1.3.0" - lodash "^4.2.0" - source-map "^0.5.0" - trim-right "^1.0.1" - -babel-generator@^6.24.0: +babel-generator@^6.18.0, babel-generator@^6.24.0: version "6.24.0" resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.24.0.tgz#eba270a8cc4ce6e09a61be43465d7c62c1f87c56" dependencies: @@ -1717,14 +1680,7 @@ eslint@^3.17.1: text-table "~0.2.0" user-home "^2.0.0" -espree@^3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/espree/-/espree-3.4.0.tgz#41656fa5628e042878025ef467e78f125cb86e1d" - dependencies: - acorn "4.0.4" - acorn-jsx "^3.0.0" - -espree@latest: +espree@^3.4.0, espree@latest: version "3.4.1" resolved "https://registry.yarnpkg.com/espree/-/espree-3.4.1.tgz#28a83ab4aaed71ed8fe0f5efe61b76a05c13c4d2" dependencies: From 8fb22223e0d4b92da7698d66842a6513a5fac8d7 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Wed, 10 May 2017 14:53:15 -0500 Subject: [PATCH 2/2] Use ensureDirSync in smoke test --- scripts/smoke-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/smoke-test.js b/scripts/smoke-test.js index f845d6da..b5ad5ae9 100755 --- a/scripts/smoke-test.js +++ b/scripts/smoke-test.js @@ -13,7 +13,7 @@ try { execSync("npm pack"); console.log("Setting up smoke test"); - fs.ensureDir(tempFolderPath); + fs.ensureDirSync(tempFolderPath); fs.writeFileSync( path.join(tempFolderPath, "package.json"),