Skip to content

Commit 9111483

Browse files
fix(core): add bootstrap.js to handle special conditions (IE11)
- RegExp sticky flag support - fix missing Symbol.toStringTag on typed array prototype
1 parent ca73b8f commit 9111483

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

build/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const configure = ({name, vueTarget, libraryTargetModule}) => (env = {}, { mode
9393
},
9494

9595
entry: [
96+
Path.resolve(__dirname, '../src/bootstrap.js'),
9697
Path.resolve(__dirname, '../src/index.ts'),
9798
],
9899

src/bootstrap.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// 1/
2+
3+
// add sticky flag support
4+
const original_RegExp = global.RegExp;
5+
6+
class PolyfilledRegExp extends global.RegExp {
7+
constructor(regex, flags = '') {
8+
if (flags.indexOf("y") === -1) {
9+
return new original_RegExp(regex, flags);
10+
}
11+
super(regex, flags.replace("y", "g"));
12+
Object.defineProperty(this, "sticky", { value: true, readonly: true });
13+
}
14+
15+
test(str) {
16+
return !!this.exec(str);
17+
}
18+
19+
exec(str) {
20+
const lastIndex = this.lastIndex;
21+
const result = super.exec(str);
22+
if (!result || result.index !== lastIndex) {
23+
this.lastIndex = 0;
24+
return null;
25+
}
26+
return result;
27+
}
28+
}
29+
30+
//RegExp = PolyfilledRegExp;
31+
global.RegExp = function(regex, flags = '') {
32+
33+
return new PolyfilledRegExp(regex, flags);
34+
}
35+
36+
37+
// 2/
38+
//
39+
// because :
40+
// - IE11 has typed array
41+
// - IE11 has no toStringTag symbol on typed array
42+
// - polyfills is "usage-pure" (no global scope pollution)
43+
// -> fix missing Symbol.toStringTag on typed array prototype (used by util > is-typed-array)
44+
// var arr = new global[typedArray]();
45+
// if (!(Symbol.toStringTag in arr)) {
46+
// ...
47+
//
48+
49+
for ( let name of [
50+
'Int8Array',
51+
'Uint8Array',
52+
'Uint8ClampedArray',
53+
'Int16Array',
54+
'Uint16Array',
55+
'Int32Array',
56+
'Uint32Array',
57+
'Float32Array',
58+
'Float64Array',
59+
'BigInt64Array',
60+
'BigUint64Array'
61+
] ) {
62+
63+
if ( global[name] )
64+
global[name].prototype[Symbol.toStringTag] = name;
65+
}
66+
67+

0 commit comments

Comments
 (0)