Skip to content

Commit

Permalink
Merge pull request #945 from zloirock/annex-b
Browse files Browse the repository at this point in the history
close #336
  • Loading branch information
zloirock authored Jun 20, 2021
2 parents 90647c4 + 5c63b94 commit fad1d44
Show file tree
Hide file tree
Showing 48 changed files with 473 additions and 60 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog
##### Unreleased
- Added missed polyfills of [Annex B](https://tc39.es/ecma262/#sec-additional-built-in-properties) features (required mainly for some non-browser engines), [#336](https://github.com/zloirock/core-js/issues/336):
- `escape`
- `unescape`
- `String.prototype.substr`
- `Date.prototype.getYear`
- `Date.prototype.setYear`
- `Date.prototype.toGMTString`
- Fixed detection of forbidden host code points in URL polyfill
- Allowed `rhino` target in `core-js-compat` / `core-js-builder`, added compat data for `rhino` 1.7.13, [#942](https://github.com/zloirock/core-js/issues/942), thanks [@gausie](https://github.com/gausie)
- `.at` marked as supported from FF90
Expand Down
104 changes: 45 additions & 59 deletions README.md

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions packages/core-js-compat/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ const data = {
safari: '7.1',
rhino: '1.7.13',
},
'es.date.get-year': {
chrome: '1',
firefox: '1',
ie: '3',
opera: '3',
safari: '1',
rhino: '1.7.13',
},
'es.date.now': {
chrome: '5',
firefox: '2',
Expand All @@ -319,6 +327,22 @@ const data = {
safari: '4.0',
rhino: '1.7.13',
},
'es.date.set-year': {
chrome: '1',
firefox: '1',
ie: '3',
opera: '3',
safari: '1',
rhino: '1.7.13',
},
'es.date.to-gmt-string': {
chrome: '1',
firefox: '1',
ie: '3',
opera: '3',
safari: '1',
rhino: '1.7.13',
},
'es.date.to-iso-string': {
chrome: '26',
firefox: '7',
Expand Down Expand Up @@ -347,6 +371,14 @@ const data = {
safari: '3.1',
rhino: '1.7.13',
},
'es.escape': {
chrome: '1',
firefox: '1',
ie: '3',
opera: '3',
safari: '1',
rhino: '1.7.13',
},
'es.function.bind': {
chrome: '7',
firefox: '4',
Expand Down Expand Up @@ -1029,6 +1061,14 @@ const data = {
firefox: '40',
safari: '10.0',
},
'es.string.substr': {
chrome: '1',
ie: '4',
firefox: '1',
opera: '4',
safari: '1',
rhino: '1.7.13',
},
'es.string.trim': {
chrome: '59',
edge: '15',
Expand Down Expand Up @@ -1345,6 +1385,14 @@ const data = {
firefox: '51',
safari: '10.0',
},
'es.unescape': {
chrome: '1',
firefox: '1',
ie: '3',
opera: '3',
safari: '1',
rhino: '1.7.13',
},
'es.weak-map': {
chrome: '51',
edge: '15',
Expand Down
8 changes: 8 additions & 0 deletions packages/core-js-compat/src/modules-by-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ module.exports = {
'esnext.symbol.matcher',
'esnext.symbol.metadata',
],
3.15: [
'es.date.get-year',
'es.date.set-year',
'es.date.to-gmt-string',
'es.escape',
'es.string.substr',
'es.unescape',
],
};
4 changes: 4 additions & 0 deletions packages/core-js/es/date/get-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../../modules/es.date.get-year');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Date', 'getYear');
5 changes: 4 additions & 1 deletion packages/core-js/es/date/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require('../../modules/es.date.get-year');
require('../../modules/es.date.now');
require('../../modules/es.date.to-json');
require('../../modules/es.date.set-year');
require('../../modules/es.date.to-gmt-string');
require('../../modules/es.date.to-iso-string');
require('../../modules/es.date.to-json');
require('../../modules/es.date.to-string');
require('../../modules/es.date.to-primitive');
var path = require('../../internals/path');
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js/es/date/set-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../../modules/es.date.set-year');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Date', 'setYear');
4 changes: 4 additions & 0 deletions packages/core-js/es/date/to-gmt-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../../modules/es.date.to-gmt-string');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Date', 'toGMTString');
4 changes: 4 additions & 0 deletions packages/core-js/es/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../modules/es.escape');
var global = require('../internals/global');

module.exports = global.escape;
1 change: 1 addition & 0 deletions packages/core-js/es/string/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require('../../modules/es.string.replace-all');
require('../../modules/es.string.search');
require('../../modules/es.string.split');
require('../../modules/es.string.starts-with');
require('../../modules/es.string.substr');
require('../../modules/es.string.trim');
require('../../modules/es.string.trim-start');
require('../../modules/es.string.trim-end');
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js/es/string/substr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../../modules/es.string.substr');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('String', 'substr');
1 change: 1 addition & 0 deletions packages/core-js/es/string/virtual/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require('../../../modules/es.string.replace-all');
require('../../../modules/es.string.search');
require('../../../modules/es.string.split');
require('../../../modules/es.string.starts-with');
require('../../../modules/es.string.substr');
require('../../../modules/es.string.trim');
require('../../../modules/es.string.trim-start');
require('../../../modules/es.string.trim-end');
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js/es/string/virtual/substr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../../../modules/es.string.substr');
var entryVirtual = require('../../../internals/entry-virtual');

module.exports = entryVirtual('String').substr;
4 changes: 4 additions & 0 deletions packages/core-js/es/unescape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('../modules/es.unescape');
var global = require('../internals/global');

module.exports = global.unescape;
3 changes: 3 additions & 0 deletions packages/core-js/features/date/get-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../stable/date/get-year');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/features/date/set-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../stable/date/set-year');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/features/date/to-gmt-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../stable/date/to-gmt-string');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/features/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../stable/escape');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/features/string/substr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../stable/string/substr');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/features/string/virtual/substr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../../stable/string/virtual/substr');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/features/unescape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../stable/unescape');

module.exports = parent;
12 changes: 12 additions & 0 deletions packages/core-js/modules/es.date.get-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
var $ = require('../internals/export');

var getFullYear = Date.prototype.getFullYear;

// `Date.prototype.getYear` method
// https://tc39.es/ecma262/#sec-date.prototype.getyear
$({ target: 'Date', proto: true }, {
getYear: function getYear() {
return getFullYear.call(this) - 1900;
}
});
18 changes: 18 additions & 0 deletions packages/core-js/modules/es.date.set-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
var $ = require('../internals/export');
var toInteger = require('../internals/to-integer');

var getTime = Date.prototype.getTime;
var setFullYear = Date.prototype.setFullYear;

// `Date.prototype.setYear` method
// https://tc39.es/ecma262/#sec-date.prototype.setyear
$({ target: 'Date', proto: true }, {
setYear: function setYear(year) {
// validate
getTime.call(this);
var yi = toInteger(year);
var yyyy = 0 <= yi && yi <= 99 ? yi + 1900 : yi;
return setFullYear.call(this, yyyy);
}
});
7 changes: 7 additions & 0 deletions packages/core-js/modules/es.date.to-gmt-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var $ = require('../internals/export');

// `Date.prototype.toGMTString` method
// https://tc39.es/ecma262/#sec-date.prototype.togmtstring
$({ target: 'Date', proto: true }, {
toGMTString: Date.prototype.toUTCString
});
35 changes: 35 additions & 0 deletions packages/core-js/modules/es.escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
var $ = require('../internals/export');

var raw = /[\w*+\-./@]/;

var hex = function (code, length) {
var result = code.toString(16);
while (result.length < length) result = '0' + result;
return result;
};

// `escape` method
// https://tc39.es/ecma262/#sec-escape-string
$({ global: true }, {
escape: function escape(string) {
var str = String(string);
var result = '';
var length = str.length;
var index = 0;
var chr, code;
while (index < length) {
chr = str.charAt(index++);
if (raw.test(chr)) {
result += chr;
} else {
code = chr.charCodeAt(0);
if (code < 256) {
result += '%' + hex(code, 2);
} else {
result += '%u' + hex(code, 4).toUpperCase();
}
}
} return result;
}
});
25 changes: 25 additions & 0 deletions packages/core-js/modules/es.string.substr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
var $ = require('../internals/export');
var requireObjectCoercible = require('../internals/require-object-coercible');
var toInteger = require('../internals/to-integer');

var slice = ''.slice;
var max = Math.max;
var min = Math.min;

// `String.prototype.substr` method
// https://tc39.es/ecma262/#sec-string.prototype.substr
$({ target: 'String', proto: true }, {
substr: function substr(start, length) {
var that = String(requireObjectCoercible(this));
var size = that.length;
var intStart = toInteger(start);
var intLength, intEnd;
if (intStart === Infinity) intStart = 0;
if (intStart < 0) intStart = max(size + intStart, 0);
intLength = length === undefined ? size : toInteger(length);
if (intLength <= 0 || intLength === Infinity) return '';
intEnd = min(intStart + intLength, size);
return intStart >= intEnd ? '' : slice.call(that, intStart, intEnd);
}
});
39 changes: 39 additions & 0 deletions packages/core-js/modules/es.unescape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
var $ = require('../internals/export');

var fromCharCode = String.fromCharCode;
var hex2 = /^[\da-f]{2}$/i;
var hex4 = /^[\da-f]{4}$/i;

// `unescape` method
// https://tc39.es/ecma262/#sec-unescape-string
$({ global: true }, {
unescape: function unescape(string) {
var str = String(string);
var result = '';
var length = str.length;
var index = 0;
var chr, slice;
while (index < length) {
chr = str.charAt(index++);
if (chr === '%') {
if (str.charAt(index) === 'u') {
slice = str.slice(index + 1, index + 5);
if (hex4.test(slice)) {
result += fromCharCode(parseInt(slice, 16));
index += 5;
continue;
}
} else {
slice = str.slice(index, index + 2);
if (hex2.test(slice)) {
result += fromCharCode(parseInt(slice, 16));
index += 2;
continue;
}
}
}
result += chr;
} return result;
}
});
3 changes: 3 additions & 0 deletions packages/core-js/stable/date/get-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../es/date/get-year');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/stable/date/set-year.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../es/date/set-year');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/stable/date/to-gmt-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../es/date/to-gmt-string');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/stable/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../es/escape');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/stable/string/substr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../es/string/substr');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/stable/string/virtual/substr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../../../es/string/virtual/substr');

module.exports = parent;
3 changes: 3 additions & 0 deletions packages/core-js/stable/unescape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var parent = require('../es/unescape');

module.exports = parent;
12 changes: 12 additions & 0 deletions tests/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,18 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(typeof instanceValues([]) === 'function');
ok(instanceValues([]).call([1, 2, 3]).next().value === 1);

for (const key of ['es', 'stable', 'features']) {
const date = new Date();
ok(load(`${ key }/date/get-year`)(date) === date.getFullYear() - 1900);
load(`${ key }/date/set-year`)(date, 1);
ok(date.getFullYear() === 1901);
ok(load(`${ key }/date/to-gmt-string`)(date) === date.toUTCString());
ok(load(`${ key }/string/substr`)('12345', 1, 3) === '234');
ok(load(`${ key }/string/virtual/substr`).call('12345', 1, 3) === '234');
ok(load(`${ key }/escape`)('!q2ф') === '%21q2%u0444');
ok(load(`${ key }/unescape`)('%21q2%u0444') === '!q2ф');
}

for (const key in compat) load(`modules/${ key }`);
}

Expand Down
Loading

0 comments on commit fad1d44

Please sign in to comment.