Skip to content

Commit

Permalink
fix some more entries of ES3 reserved words, #980
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 2, 2021
1 parent 1b93419 commit f622c80
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 77 deletions.
134 changes: 67 additions & 67 deletions packages/core-js/modules/web.url.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ var userinfoPercentEncodeSet = assign({}, pathPercentEncodeSet, {
'/': 1, ':': 1, ';': 1, '=': 1, '@': 1, '[': 1, '\\': 1, ']': 1, '^': 1, '|': 1
});

var percentEncode = function (char, set) {
var code = codeAt(char, 0);
return code > 0x20 && code < 0x7F && !has(set, char) ? char : encodeURIComponent(char);
var percentEncode = function (chr, set) {
var code = codeAt(chr, 0);
return code > 0x20 && code < 0x7F && !has(set, chr) ? chr : encodeURIComponent(chr);
};

var specialSchemes = {
Expand Down Expand Up @@ -340,7 +340,7 @@ var parseURL = function (url, input, stateOverride, base) {
var seenAt = false;
var seenBracket = false;
var seenPasswordToken = false;
var codePoints, char, bufferCodePoints, failure;
var codePoints, chr, bufferCodePoints, failure;

if (!stateOverride) {
url.scheme = '';
Expand All @@ -360,11 +360,11 @@ var parseURL = function (url, input, stateOverride, base) {
codePoints = arrayFrom(input);

while (pointer <= codePoints.length) {
char = codePoints[pointer];
chr = codePoints[pointer];
switch (state) {
case SCHEME_START:
if (char && ALPHA.test(char)) {
buffer += char.toLowerCase();
if (chr && ALPHA.test(chr)) {
buffer += chr.toLowerCase();
state = SCHEME;
} else if (!stateOverride) {
state = NO_SCHEME;
Expand All @@ -373,9 +373,9 @@ var parseURL = function (url, input, stateOverride, base) {
break;

case SCHEME:
if (char && (ALPHANUMERIC.test(char) || char == '+' || char == '-' || char == '.')) {
buffer += char.toLowerCase();
} else if (char == ':') {
if (chr && (ALPHANUMERIC.test(chr) || chr == '+' || chr == '-' || chr == '.')) {
buffer += chr.toLowerCase();
} else if (chr == ':') {
if (stateOverride && (
(isSpecial(url) != has(specialSchemes, buffer)) ||
(buffer == 'file' && (includesCredentials(url) || url.port !== null)) ||
Expand Down Expand Up @@ -410,8 +410,8 @@ var parseURL = function (url, input, stateOverride, base) {
break;

case NO_SCHEME:
if (!base || (base.cannotBeABaseURL && char != '#')) return INVALID_SCHEME;
if (base.cannotBeABaseURL && char == '#') {
if (!base || (base.cannotBeABaseURL && chr != '#')) return INVALID_SCHEME;
if (base.cannotBeABaseURL && chr == '#') {
url.scheme = base.scheme;
url.path = base.path.slice();
url.query = base.query;
Expand All @@ -424,7 +424,7 @@ var parseURL = function (url, input, stateOverride, base) {
continue;

case SPECIAL_RELATIVE_OR_AUTHORITY:
if (char == '/' && codePoints[pointer + 1] == '/') {
if (chr == '/' && codePoints[pointer + 1] == '/') {
state = SPECIAL_AUTHORITY_IGNORE_SLASHES;
pointer++;
} else {
Expand All @@ -433,7 +433,7 @@ var parseURL = function (url, input, stateOverride, base) {
} break;

case PATH_OR_AUTHORITY:
if (char == '/') {
if (chr == '/') {
state = AUTHORITY;
break;
} else {
Expand All @@ -443,24 +443,24 @@ var parseURL = function (url, input, stateOverride, base) {

case RELATIVE:
url.scheme = base.scheme;
if (char == EOF) {
if (chr == EOF) {
url.username = base.username;
url.password = base.password;
url.host = base.host;
url.port = base.port;
url.path = base.path.slice();
url.query = base.query;
} else if (char == '/' || (char == '\\' && isSpecial(url))) {
} else if (chr == '/' || (chr == '\\' && isSpecial(url))) {
state = RELATIVE_SLASH;
} else if (char == '?') {
} else if (chr == '?') {
url.username = base.username;
url.password = base.password;
url.host = base.host;
url.port = base.port;
url.path = base.path.slice();
url.query = '';
state = QUERY;
} else if (char == '#') {
} else if (chr == '#') {
url.username = base.username;
url.password = base.password;
url.host = base.host;
Expand All @@ -481,9 +481,9 @@ var parseURL = function (url, input, stateOverride, base) {
} break;

case RELATIVE_SLASH:
if (isSpecial(url) && (char == '/' || char == '\\')) {
if (isSpecial(url) && (chr == '/' || chr == '\\')) {
state = SPECIAL_AUTHORITY_IGNORE_SLASHES;
} else if (char == '/') {
} else if (chr == '/') {
state = AUTHORITY;
} else {
url.username = base.username;
Expand All @@ -496,18 +496,18 @@ var parseURL = function (url, input, stateOverride, base) {

case SPECIAL_AUTHORITY_SLASHES:
state = SPECIAL_AUTHORITY_IGNORE_SLASHES;
if (char != '/' || buffer.charAt(pointer + 1) != '/') continue;
if (chr != '/' || buffer.charAt(pointer + 1) != '/') continue;
pointer++;
break;

case SPECIAL_AUTHORITY_IGNORE_SLASHES:
if (char != '/' && char != '\\') {
if (chr != '/' && chr != '\\') {
state = AUTHORITY;
continue;
} break;

case AUTHORITY:
if (char == '@') {
if (chr == '@') {
if (seenAt) buffer = '%40' + buffer;
seenAt = true;
bufferCodePoints = arrayFrom(buffer);
Expand All @@ -523,31 +523,31 @@ var parseURL = function (url, input, stateOverride, base) {
}
buffer = '';
} else if (
char == EOF || char == '/' || char == '?' || char == '#' ||
(char == '\\' && isSpecial(url))
chr == EOF || chr == '/' || chr == '?' || chr == '#' ||
(chr == '\\' && isSpecial(url))
) {
if (seenAt && buffer == '') return INVALID_AUTHORITY;
pointer -= arrayFrom(buffer).length + 1;
buffer = '';
state = HOST;
} else buffer += char;
} else buffer += chr;
break;

case HOST:
case HOSTNAME:
if (stateOverride && url.scheme == 'file') {
state = FILE_HOST;
continue;
} else if (char == ':' && !seenBracket) {
} else if (chr == ':' && !seenBracket) {
if (buffer == '') return INVALID_HOST;
failure = parseHost(url, buffer);
if (failure) return failure;
buffer = '';
state = PORT;
if (stateOverride == HOSTNAME) return;
} else if (
char == EOF || char == '/' || char == '?' || char == '#' ||
(char == '\\' && isSpecial(url))
chr == EOF || chr == '/' || chr == '?' || chr == '#' ||
(chr == '\\' && isSpecial(url))
) {
if (isSpecial(url) && buffer == '') return INVALID_HOST;
if (stateOverride && buffer == '' && (includesCredentials(url) || url.port !== null)) return;
Expand All @@ -558,17 +558,17 @@ var parseURL = function (url, input, stateOverride, base) {
if (stateOverride) return;
continue;
} else {
if (char == '[') seenBracket = true;
else if (char == ']') seenBracket = false;
buffer += char;
if (chr == '[') seenBracket = true;
else if (chr == ']') seenBracket = false;
buffer += chr;
} break;

case PORT:
if (DIGIT.test(char)) {
buffer += char;
if (DIGIT.test(chr)) {
buffer += chr;
} else if (
char == EOF || char == '/' || char == '?' || char == '#' ||
(char == '\\' && isSpecial(url)) ||
chr == EOF || chr == '/' || chr == '?' || chr == '#' ||
(chr == '\\' && isSpecial(url)) ||
stateOverride
) {
if (buffer != '') {
Expand All @@ -585,18 +585,18 @@ var parseURL = function (url, input, stateOverride, base) {

case FILE:
url.scheme = 'file';
if (char == '/' || char == '\\') state = FILE_SLASH;
if (chr == '/' || chr == '\\') state = FILE_SLASH;
else if (base && base.scheme == 'file') {
if (char == EOF) {
if (chr == EOF) {
url.host = base.host;
url.path = base.path.slice();
url.query = base.query;
} else if (char == '?') {
} else if (chr == '?') {
url.host = base.host;
url.path = base.path.slice();
url.query = '';
state = QUERY;
} else if (char == '#') {
} else if (chr == '#') {
url.host = base.host;
url.path = base.path.slice();
url.query = base.query;
Expand All @@ -617,7 +617,7 @@ var parseURL = function (url, input, stateOverride, base) {
} break;

case FILE_SLASH:
if (char == '/' || char == '\\') {
if (chr == '/' || chr == '\\') {
state = FILE_HOST;
break;
}
Expand All @@ -629,7 +629,7 @@ var parseURL = function (url, input, stateOverride, base) {
continue;

case FILE_HOST:
if (char == EOF || char == '/' || char == '\\' || char == '?' || char == '#') {
if (chr == EOF || chr == '/' || chr == '\\' || chr == '?' || chr == '#') {
if (!stateOverride && isWindowsDriveLetter(buffer)) {
state = PATH;
} else if (buffer == '') {
Expand All @@ -644,37 +644,37 @@ var parseURL = function (url, input, stateOverride, base) {
buffer = '';
state = PATH_START;
} continue;
} else buffer += char;
} else buffer += chr;
break;

case PATH_START:
if (isSpecial(url)) {
state = PATH;
if (char != '/' && char != '\\') continue;
} else if (!stateOverride && char == '?') {
if (chr != '/' && chr != '\\') continue;
} else if (!stateOverride && chr == '?') {
url.query = '';
state = QUERY;
} else if (!stateOverride && char == '#') {
} else if (!stateOverride && chr == '#') {
url.fragment = '';
state = FRAGMENT;
} else if (char != EOF) {
} else if (chr != EOF) {
state = PATH;
if (char != '/') continue;
if (chr != '/') continue;
} break;

case PATH:
if (
char == EOF || char == '/' ||
(char == '\\' && isSpecial(url)) ||
(!stateOverride && (char == '?' || char == '#'))
chr == EOF || chr == '/' ||
(chr == '\\' && isSpecial(url)) ||
(!stateOverride && (chr == '?' || chr == '#'))
) {
if (isDoubleDot(buffer)) {
shortenURLsPath(url);
if (char != '/' && !(char == '\\' && isSpecial(url))) {
if (chr != '/' && !(chr == '\\' && isSpecial(url))) {
url.path.push('');
}
} else if (isSingleDot(buffer)) {
if (char != '/' && !(char == '\\' && isSpecial(url))) {
if (chr != '/' && !(chr == '\\' && isSpecial(url))) {
url.path.push('');
}
} else {
Expand All @@ -685,45 +685,45 @@ var parseURL = function (url, input, stateOverride, base) {
url.path.push(buffer);
}
buffer = '';
if (url.scheme == 'file' && (char == EOF || char == '?' || char == '#')) {
if (url.scheme == 'file' && (chr == EOF || chr == '?' || chr == '#')) {
while (url.path.length > 1 && url.path[0] === '') {
url.path.shift();
}
}
if (char == '?') {
if (chr == '?') {
url.query = '';
state = QUERY;
} else if (char == '#') {
} else if (chr == '#') {
url.fragment = '';
state = FRAGMENT;
}
} else {
buffer += percentEncode(char, pathPercentEncodeSet);
buffer += percentEncode(chr, pathPercentEncodeSet);
} break;

case CANNOT_BE_A_BASE_URL_PATH:
if (char == '?') {
if (chr == '?') {
url.query = '';
state = QUERY;
} else if (char == '#') {
} else if (chr == '#') {
url.fragment = '';
state = FRAGMENT;
} else if (char != EOF) {
url.path[0] += percentEncode(char, C0ControlPercentEncodeSet);
} else if (chr != EOF) {
url.path[0] += percentEncode(chr, C0ControlPercentEncodeSet);
} break;

case QUERY:
if (!stateOverride && char == '#') {
if (!stateOverride && chr == '#') {
url.fragment = '';
state = FRAGMENT;
} else if (char != EOF) {
if (char == "'" && isSpecial(url)) url.query += '%27';
else if (char == '#') url.query += '%23';
else url.query += percentEncode(char, C0ControlPercentEncodeSet);
} else if (chr != EOF) {
if (chr == "'" && isSpecial(url)) url.query += '%27';
else if (chr == '#') url.query += '%23';
else url.query += percentEncode(chr, C0ControlPercentEncodeSet);
} break;

case FRAGMENT:
if (char != EOF) url.fragment += percentEncode(char, fragmentPercentEncodeSet);
if (chr != EOF) url.fragment += percentEncode(chr, fragmentPercentEncodeSet);
break;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/helpers/qunit-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ QUnit.assert.nonEnumerable = function (O, key, message) {
};

QUnit.assert.notThrows = function (fn, message) {
let throws, result, error;
let thrown, result, error;
try {
result = fn();
throws = false;
thrown = false;
} catch (err) {
throws = true;
thrown = true;
error = err;
}
this.pushResult({
result: !throws && result,
actual: throws ? error : result,
expected: throws ? undefined : true,
result: !thrown && result,
actual: thrown ? error : result,
expected: thrown ? undefined : true,
message: message || 'does not throw',
});
};
Expand Down
4 changes: 2 additions & 2 deletions tests/pure/es.object.assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ QUnit.test('Object.assign', assert => {
string = 'abcdefghijklmnopqrst';
const result = {};
for (let i = 0, { length } = string; i < length; ++i) {
const char = string.charAt(i);
result[char] = char;
const chr = string.charAt(i);
result[chr] = chr;
}
assert.strictEqual(keys(assign({}, result)).join(''), string);
});
Loading

0 comments on commit f622c80

Please sign in to comment.