Skip to content

Commit

Permalink
[es-shims] Add support for the String.prototype Annex B methods (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo authored Sep 22, 2021
1 parent a8e0ddc commit fa4f9f3
Show file tree
Hide file tree
Showing 22 changed files with 473 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/babel-plugin-polyfill-es-shims/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
169 changes: 169 additions & 0 deletions packages/babel-plugin-polyfill-es-shims/data/polyfills.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
16 changes: 0 additions & 16 deletions packages/babel-plugin-polyfill-es-shims/missing-polyfills.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
4 changes: 2 additions & 2 deletions packages/babel-plugin-polyfill-es-shims/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}),
Expand Down
41 changes: 38 additions & 3 deletions packages/babel-plugin-polyfill-es-shims/src/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"validateLogs": true,
"targets": { "ie": "11" },
"plugins": [
[
"@@/polyfill-es-shims",
{
"method": "usage-global",
"missingDependencies": {
"log": "per-file",
"all": true
}
}
]
]
}
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"validateLogs": true,
"plugins": [
[
"@@/polyfill-es-shims",
{
"method": "usage-global",
"missingDependencies": {
"log": "per-file",
"all": true
}
}
]
]
}
Loading

0 comments on commit fa4f9f3

Please sign in to comment.