From fa4f9f3c42d50702b69f2aa8943840a5ba42c3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 22 Sep 2021 19:37:49 +0200 Subject: [PATCH] [es-shims] Add support for the `String.prototype` Annex B methods (#103) --- .../babel-plugin-polyfill-es-shims/README.md | 1 + .../data/polyfills.json | 169 ++++++++++++++++++ .../missing-polyfills.md | 16 -- .../src/index.js | 4 +- .../src/mappings.js | 41 ++++- .../annex-b-string-ie-11/input.mjs | 13 ++ .../annex-b-string-ie-11/options.json | 16 ++ .../annex-b-string-ie-11/output.mjs | 26 +++ .../annex-b-string-ie-11/stderr.txt | 4 + .../usage-global/annex-b-string/input.mjs | 13 ++ .../usage-global/annex-b-string/options.json | 15 ++ .../usage-global/annex-b-string/output.mjs | 26 +++ .../usage-global/annex-b-string/stderr.txt | 4 + .../usage-pure/annex-b-string-check/input.mjs | 13 ++ .../annex-b-string-check/options.json | 15 ++ .../annex-b-string-check/output.mjs | 28 +++ .../annex-b-string-check/stderr.txt | 4 + .../usage-pure/annex-b-string/input.mjs | 13 ++ .../usage-pure/annex-b-string/options.json | 15 ++ .../usage-pure/annex-b-string/output.mjs | 39 ++++ .../usage-pure/annex-b-string/stderr.txt | 4 + .../build-es-shims-data/es-shims-features.js | 15 ++ 22 files changed, 473 insertions(+), 21 deletions(-) create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/input.mjs create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/options.json create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/output.mjs create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/stderr.txt create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/input.mjs create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/options.json create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/output.mjs create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/stderr.txt create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/input.mjs create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/options.json create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/output.mjs create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/stderr.txt create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/input.mjs create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/options.json create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/output.mjs create mode 100644 packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/stderr.txt diff --git a/packages/babel-plugin-polyfill-es-shims/README.md b/packages/babel-plugin-polyfill-es-shims/README.md index 80cf47cd..16d316e5 100644 --- a/packages/babel-plugin-polyfill-es-shims/README.md +++ b/packages/babel-plugin-polyfill-es-shims/README.md @@ -84,6 +84,7 @@ This plugin supports the following `es-shims` polyfills. | `String.prototype.includes` | [`string.prototype.includes`](https://github.com/mathiasbynens/String.prototype.includes) | [@mathiasbynens](https://github.com/mathiasbynens) | | `String.prototype.repeat` | [`string.prototype.repeat`](https://github.com/mathiasbynens/String.prototype.repeat) | [@mathiasbynens](https://github.com/mathiasbynens) | | `String.prototype.startWith` | [`string.prototype.startwith`](https://github.com/mathiasbynens/String.prototype.startsWith) | [@mathiasbynens](https://github.com/mathiasbynens) | +| Annex B `String.prototype.*` | [`es-string-html-methods`](https://github.com/es-shims/es-string-html-methods) | ### ES2016 diff --git a/packages/babel-plugin-polyfill-es-shims/data/polyfills.json b/packages/babel-plugin-polyfill-es-shims/data/polyfills.json index 73a476ec..1f4d2e42 100644 --- a/packages/babel-plugin-polyfill-es-shims/data/polyfills.json +++ b/packages/babel-plugin-polyfill-es-shims/data/polyfills.json @@ -824,5 +824,174 @@ "ios": "12.2", "samsung": "10", "electron": "5" + }, + "String.prototype.anchor": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.big": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.blink": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.bold": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.fixed": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.fontcolor": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.fontsize": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.italics": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.link": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.small": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.strike": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.sub": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" + }, + "String.prototype.sup": { + "chrome": "5", + "opera": "15", + "edge": "12", + "firefox": "17", + "safari": "6", + "node": "0.10", + "android": "4", + "ios": "7", + "phantom": "2", + "samsung": "1", + "electron": "0.20" } } diff --git a/packages/babel-plugin-polyfill-es-shims/missing-polyfills.md b/packages/babel-plugin-polyfill-es-shims/missing-polyfills.md index 368ef0d0..0d55ace9 100644 --- a/packages/babel-plugin-polyfill-es-shims/missing-polyfills.md +++ b/packages/babel-plugin-polyfill-es-shims/missing-polyfills.md @@ -37,19 +37,3 @@ - `Symbol.replace` (and corresponding `String#replace` support) - `Symbol.search` (and corresponding `String#search` support) - `Symbol.split` (and corresponding `String#split` support) - -Annex B HTML methods: - -- `String.prototype.anchor()` -- `String.prototype.big()` -- `String.prototype.blink()` -- `String.prototype.bold()` -- `String.prototype.fixed()` -- `String.prototype.fontcolor()` -- `String.prototype.fontsize()` -- `String.prototype.italics()` -- `String.prototype.link()` -- `String.prototype.small()` -- `String.prototype.strike()` -- `String.prototype.sub()` -- `String.prototype.sup()` diff --git a/packages/babel-plugin-polyfill-es-shims/src/index.js b/packages/babel-plugin-polyfill-es-shims/src/index.js index b05e21a7..89606511 100644 --- a/packages/babel-plugin-polyfill-es-shims/src/index.js +++ b/packages/babel-plugin-polyfill-es-shims/src/index.js @@ -57,7 +57,7 @@ export default defineProvider<{||}>(function({ assertDependency(desc.package, desc.version); debug(desc.name); - return utils.injectDefaultImport(desc.package, desc.name); + return utils.injectDefaultImport(desc.path, desc.name); } const seen = new WeakSet(); @@ -71,7 +71,7 @@ export default defineProvider<{||}>(function({ assertDependency(desc.package, desc.version); - utils.injectGlobalImport(`${desc.package}/auto`); + utils.injectGlobalImport(`${desc.path}/auto`); debug(desc.name); }), diff --git a/packages/babel-plugin-polyfill-es-shims/src/mappings.js b/packages/babel-plugin-polyfill-es-shims/src/mappings.js index 2b2145ef..9599f61a 100644 --- a/packages/babel-plugin-polyfill-es-shims/src/mappings.js +++ b/packages/babel-plugin-polyfill-es-shims/src/mappings.js @@ -14,6 +14,7 @@ export type Descriptor = { name: string, version: string, package: string, + path: string, // This is different from .package for multi-entry-point packages pure?: false, global?: false, thisCheck?: (thisObj: Object) => Object, @@ -139,8 +140,35 @@ defineInstance( getter, ); -function createDescriptor(name, version, pkg = name.toLowerCase()) { - return { name, version, package: pkg }; +// Annex B +for (const name of [ + "anchor", + "big", + "blink", + "bold", + "fixed", + "fontcolor", + "fontsize", + "italics", + "link", + "small", + "strike", + "sub", + "sup", +]) { + defineInstance("String", name, "1.0.0", stringCheck, { + pkg: `es-string-html-methods`, + subfolder: name, + }); +} + +function createDescriptor(name, version, pkg = name.toLowerCase(), subfolder) { + return { + name, + version, + package: pkg, + path: subfolder ? `${pkg}/${subfolder}` : pkg, + }; } function defineGlobal(name, version, pkg) { @@ -164,16 +192,23 @@ function defineInstance( getter = false, exclude, pkg, + subfolder, }: { getter?: boolean, exclude?: (meta: MetaDescriptor) => boolean, pkg?: string, + subfolder?: string, } = {}, ) { if (!has(InstanceProperties, property)) InstanceProperties[property] = []; InstanceProperties[property].push({ - ...createDescriptor(`${object}.prototype.${property}`, version, pkg), + ...createDescriptor( + `${object}.prototype.${property}`, + version, + pkg, + subfolder, + ), thisCheck, exclude, getter, diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/input.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/input.mjs new file mode 100644 index 00000000..f3e48893 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/input.mjs @@ -0,0 +1,13 @@ +str.anchor(); +str.big(); +str.blink(); +str.bold(); +str.fixed(); +str.fontcolor(); +str.fontsize(); +str.italics(); +str.link(); +str.small(); +str.strike(); +str.sub(); +str.sup(); diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/options.json b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/options.json new file mode 100644 index 00000000..7937464d --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/options.json @@ -0,0 +1,16 @@ +{ + "validateLogs": true, + "targets": { "ie": "11" }, + "plugins": [ + [ + "@@/polyfill-es-shims", + { + "method": "usage-global", + "missingDependencies": { + "log": "per-file", + "all": true + } + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/output.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/output.mjs new file mode 100644 index 00000000..d9f68ebd --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/output.mjs @@ -0,0 +1,26 @@ +import "es-string-html-methods/anchor/auto"; +import "es-string-html-methods/big/auto"; +import "es-string-html-methods/blink/auto"; +import "es-string-html-methods/bold/auto"; +import "es-string-html-methods/fixed/auto"; +import "es-string-html-methods/fontcolor/auto"; +import "es-string-html-methods/fontsize/auto"; +import "es-string-html-methods/italics/auto"; +import "es-string-html-methods/link/auto"; +import "es-string-html-methods/small/auto"; +import "es-string-html-methods/strike/auto"; +import "es-string-html-methods/sub/auto"; +import "es-string-html-methods/sup/auto"; +str.anchor(); +str.big(); +str.blink(); +str.bold(); +str.fixed(); +str.fontcolor(); +str.fontsize(); +str.italics(); +str.link(); +str.small(); +str.strike(); +str.sub(); +str.sup(); diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/stderr.txt b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/stderr.txt new file mode 100644 index 00000000..461cfe09 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string-ie-11/stderr.txt @@ -0,0 +1,4 @@ +Some polyfills have been added but are not present in your dependencies. +Please run one of the following commands: + npm install --save es-string-html-methods@^1.0.0 + yarn add es-string-html-methods@^1.0.0 diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/input.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/input.mjs new file mode 100644 index 00000000..f3e48893 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/input.mjs @@ -0,0 +1,13 @@ +str.anchor(); +str.big(); +str.blink(); +str.bold(); +str.fixed(); +str.fontcolor(); +str.fontsize(); +str.italics(); +str.link(); +str.small(); +str.strike(); +str.sub(); +str.sup(); diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/options.json b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/options.json new file mode 100644 index 00000000..0a3e1333 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/options.json @@ -0,0 +1,15 @@ +{ + "validateLogs": true, + "plugins": [ + [ + "@@/polyfill-es-shims", + { + "method": "usage-global", + "missingDependencies": { + "log": "per-file", + "all": true + } + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/output.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/output.mjs new file mode 100644 index 00000000..d9f68ebd --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/output.mjs @@ -0,0 +1,26 @@ +import "es-string-html-methods/anchor/auto"; +import "es-string-html-methods/big/auto"; +import "es-string-html-methods/blink/auto"; +import "es-string-html-methods/bold/auto"; +import "es-string-html-methods/fixed/auto"; +import "es-string-html-methods/fontcolor/auto"; +import "es-string-html-methods/fontsize/auto"; +import "es-string-html-methods/italics/auto"; +import "es-string-html-methods/link/auto"; +import "es-string-html-methods/small/auto"; +import "es-string-html-methods/strike/auto"; +import "es-string-html-methods/sub/auto"; +import "es-string-html-methods/sup/auto"; +str.anchor(); +str.big(); +str.blink(); +str.bold(); +str.fixed(); +str.fontcolor(); +str.fontsize(); +str.italics(); +str.link(); +str.small(); +str.strike(); +str.sub(); +str.sup(); diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/stderr.txt b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/stderr.txt new file mode 100644 index 00000000..461cfe09 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-global/annex-b-string/stderr.txt @@ -0,0 +1,4 @@ +Some polyfills have been added but are not present in your dependencies. +Please run one of the following commands: + npm install --save es-string-html-methods@^1.0.0 + yarn add es-string-html-methods@^1.0.0 diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/input.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/input.mjs new file mode 100644 index 00000000..f3e48893 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/input.mjs @@ -0,0 +1,13 @@ +str.anchor(); +str.big(); +str.blink(); +str.bold(); +str.fixed(); +str.fontcolor(); +str.fontsize(); +str.italics(); +str.link(); +str.small(); +str.strike(); +str.sub(); +str.sup(); diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/options.json b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/options.json new file mode 100644 index 00000000..784125a7 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/options.json @@ -0,0 +1,15 @@ +{ + "validateLogs": true, + "plugins": [ + [ + "@@/polyfill-es-shims", + { + "method": "usage-pure", + "missingDependencies": { + "log": "per-file", + "all": true + } + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/output.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/output.mjs new file mode 100644 index 00000000..3b8ac9b4 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/output.mjs @@ -0,0 +1,28 @@ +var _str, _str2, _str3, _str4, _str5, _str6, _str7, _str8, _str9, _str10, _str11, _str12, _str13; + +import _StringPrototypeAnchor from "es-string-html-methods/anchor"; +import _StringPrototypeBig from "es-string-html-methods/big"; +import _StringPrototypeBlink from "es-string-html-methods/blink"; +import _StringPrototypeBold from "es-string-html-methods/bold"; +import _StringPrototypeFixed from "es-string-html-methods/fixed"; +import _StringPrototypeFontcolor from "es-string-html-methods/fontcolor"; +import _StringPrototypeFontsize from "es-string-html-methods/fontsize"; +import _StringPrototypeItalics from "es-string-html-methods/italics"; +import _StringPrototypeLink from "es-string-html-methods/link"; +import _StringPrototypeSmall from "es-string-html-methods/small"; +import _StringPrototypeStrike from "es-string-html-methods/strike"; +import _StringPrototypeSub from "es-string-html-methods/sub"; +import _StringPrototypeSup from "es-string-html-methods/sup"; +(_str = str, typeof _str === "string" ? _StringPrototypeAnchor : Function.call.bind(_str.anchor))(_str); +(_str2 = str, typeof _str2 === "string" ? _StringPrototypeBig : Function.call.bind(_str2.big))(_str2); +(_str3 = str, typeof _str3 === "string" ? _StringPrototypeBlink : Function.call.bind(_str3.blink))(_str3); +(_str4 = str, typeof _str4 === "string" ? _StringPrototypeBold : Function.call.bind(_str4.bold))(_str4); +(_str5 = str, typeof _str5 === "string" ? _StringPrototypeFixed : Function.call.bind(_str5.fixed))(_str5); +(_str6 = str, typeof _str6 === "string" ? _StringPrototypeFontcolor : Function.call.bind(_str6.fontcolor))(_str6); +(_str7 = str, typeof _str7 === "string" ? _StringPrototypeFontsize : Function.call.bind(_str7.fontsize))(_str7); +(_str8 = str, typeof _str8 === "string" ? _StringPrototypeItalics : Function.call.bind(_str8.italics))(_str8); +(_str9 = str, typeof _str9 === "string" ? _StringPrototypeLink : Function.call.bind(_str9.link))(_str9); +(_str10 = str, typeof _str10 === "string" ? _StringPrototypeSmall : Function.call.bind(_str10.small))(_str10); +(_str11 = str, typeof _str11 === "string" ? _StringPrototypeStrike : Function.call.bind(_str11.strike))(_str11); +(_str12 = str, typeof _str12 === "string" ? _StringPrototypeSub : Function.call.bind(_str12.sub))(_str12); +(_str13 = str, typeof _str13 === "string" ? _StringPrototypeSup : Function.call.bind(_str13.sup))(_str13); diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/stderr.txt b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/stderr.txt new file mode 100644 index 00000000..461cfe09 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string-check/stderr.txt @@ -0,0 +1,4 @@ +Some polyfills have been added but are not present in your dependencies. +Please run one of the following commands: + npm install --save es-string-html-methods@^1.0.0 + yarn add es-string-html-methods@^1.0.0 diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/input.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/input.mjs new file mode 100644 index 00000000..e3e61d03 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/input.mjs @@ -0,0 +1,13 @@ +"str".anchor(); +"str".big(); +"str".blink(); +"str".bold(); +"str".fixed(); +"str".fontcolor(); +"str".fontsize(); +"str".italics(); +"str".link(); +"str".small(); +"str".strike(); +"str".sub(); +"str".sup(); diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/options.json b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/options.json new file mode 100644 index 00000000..784125a7 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/options.json @@ -0,0 +1,15 @@ +{ + "validateLogs": true, + "plugins": [ + [ + "@@/polyfill-es-shims", + { + "method": "usage-pure", + "missingDependencies": { + "log": "per-file", + "all": true + } + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/output.mjs b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/output.mjs new file mode 100644 index 00000000..ae0092b9 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/output.mjs @@ -0,0 +1,39 @@ +import _StringPrototypeAnchor from "es-string-html-methods/anchor"; +import _StringPrototypeBig from "es-string-html-methods/big"; +import _StringPrototypeBlink from "es-string-html-methods/blink"; +import _StringPrototypeBold from "es-string-html-methods/bold"; +import _StringPrototypeFixed from "es-string-html-methods/fixed"; +import _StringPrototypeFontcolor from "es-string-html-methods/fontcolor"; +import _StringPrototypeFontsize from "es-string-html-methods/fontsize"; +import _StringPrototypeItalics from "es-string-html-methods/italics"; +import _StringPrototypeLink from "es-string-html-methods/link"; +import _StringPrototypeSmall from "es-string-html-methods/small"; +import _StringPrototypeStrike from "es-string-html-methods/strike"; +import _StringPrototypeSub from "es-string-html-methods/sub"; +import _StringPrototypeSup from "es-string-html-methods/sup"; + +_StringPrototypeAnchor("str"); + +_StringPrototypeBig("str"); + +_StringPrototypeBlink("str"); + +_StringPrototypeBold("str"); + +_StringPrototypeFixed("str"); + +_StringPrototypeFontcolor("str"); + +_StringPrototypeFontsize("str"); + +_StringPrototypeItalics("str"); + +_StringPrototypeLink("str"); + +_StringPrototypeSmall("str"); + +_StringPrototypeStrike("str"); + +_StringPrototypeSub("str"); + +_StringPrototypeSup("str"); diff --git a/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/stderr.txt b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/stderr.txt new file mode 100644 index 00000000..461cfe09 --- /dev/null +++ b/packages/babel-plugin-polyfill-es-shims/test/fixtures/usage-pure/annex-b-string/stderr.txt @@ -0,0 +1,4 @@ +Some polyfills have been added but are not present in your dependencies. +Please run one of the following commands: + npm install --save es-string-html-methods@^1.0.0 + yarn add es-string-html-methods@^1.0.0 diff --git a/scripts/build-es-shims-data/es-shims-features.js b/scripts/build-es-shims-data/es-shims-features.js index 2c25bef3..0f33a164 100644 --- a/scripts/build-es-shims-data/es-shims-features.js +++ b/scripts/build-es-shims-data/es-shims-features.js @@ -102,4 +102,19 @@ module.exports = { "String.prototype.trimRight": "string trimming / String.prototype.trimRight", "String.prototype.trimStart": "string trimming / String.prototype.trimStart", "Symbol.prototype.description": "Symbol.prototype.description", + + // Annex B + "String.prototype.anchor": "String.prototype HTML methods", + "String.prototype.big": "String.prototype HTML methods", + "String.prototype.blink": "String.prototype HTML methods", + "String.prototype.bold": "String.prototype HTML methods", + "String.prototype.fixed": "String.prototype HTML methods", + "String.prototype.fontcolor": "String.prototype HTML methods", + "String.prototype.fontsize": "String.prototype HTML methods", + "String.prototype.italics": "String.prototype HTML methods", + "String.prototype.link": "String.prototype HTML methods", + "String.prototype.small": "String.prototype HTML methods", + "String.prototype.strike": "String.prototype HTML methods", + "String.prototype.sub": "String.prototype HTML methods", + "String.prototype.sup": "String.prototype HTML methods", };