Skip to content

Commit 47e9bd1

Browse files
authored
Correctly handling number key (#5328)
* handling __proto__ * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling __proto__ key * handling string key * handling __proto__ key * handling string name * handling __proto__ key * handling __proto__ key * handling string name * hanlding __proto__ key * handling __proto__ key * handling __proto__ key * handling string name * handling string name * handling string name * handling __proto__ key * handling __proto__ key * handling __proto__ key * Correctly handling number key * Correctly handling number key * Correctly handling number key
1 parent c249413 commit 47e9bd1

File tree

10 files changed

+98
-2
lines changed

10 files changed

+98
-2
lines changed

src/utils/identifierHelpers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ export function makeLegal(value: string): string {
2525
}
2626

2727
export const VALID_IDENTIFIER_REGEXP = /^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*$/u;
28-
export const NUMBER_REGEXP = /^\d+$/;
28+
const NUMBER_REGEXP = /^(?:0|[1-9]\d*)$/;
2929

3030
export function stringifyObjectKeyIfNeeded(key: string) {
31-
if (VALID_IDENTIFIER_REGEXP.test(key) || NUMBER_REGEXP.test(key)) {
31+
if (VALID_IDENTIFIER_REGEXP.test(key)) {
3232
return key === '__proto__' ? '["__proto__"]' : key;
3333
}
34+
if (NUMBER_REGEXP.test(key) && +key <= Number.MAX_SAFE_INTEGER) {
35+
return key;
36+
}
3437
return JSON.stringify(key);
3538
}
3639

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = defineTest({
2+
description: 'index key',
3+
options: {
4+
external: ['x'],
5+
output: {
6+
globals: {
7+
x: 'x'
8+
}
9+
}
10+
}
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
define(['x'], (function (x$1) { 'use strict';
2+
3+
var x = /*#__PURE__*/Object.freeze({
4+
__proto__: null,
5+
"00": x$1["00"],
6+
"9007199254740993": x$1["9007199254740993"]
7+
});
8+
9+
console.log(x);
10+
11+
}));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
var x$1 = require('x');
4+
5+
var x = /*#__PURE__*/Object.freeze({
6+
__proto__: null,
7+
"00": x$1["00"],
8+
"9007199254740993": x$1["9007199254740993"]
9+
});
10+
11+
console.log(x);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { "00" as _00, "9007199254740993" as _9007199254740993 } from 'x';
2+
3+
var x = /*#__PURE__*/Object.freeze({
4+
__proto__: null,
5+
"00": _00,
6+
"9007199254740993": _9007199254740993
7+
});
8+
9+
console.log(x);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(function (x$1) {
2+
'use strict';
3+
4+
var x = /*#__PURE__*/Object.freeze({
5+
__proto__: null,
6+
"00": x$1["00"],
7+
"9007199254740993": x$1["9007199254740993"]
8+
});
9+
10+
console.log(x);
11+
12+
})(x);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
System.register(['x'], (function () {
2+
'use strict';
3+
var _00, _9007199254740993;
4+
return {
5+
setters: [function (module) {
6+
_00 = module["00"];
7+
_9007199254740993 = module["9007199254740993"];
8+
}],
9+
execute: (function () {
10+
11+
var x = /*#__PURE__*/Object.freeze({
12+
__proto__: null,
13+
"00": _00,
14+
"9007199254740993": _9007199254740993
15+
});
16+
17+
console.log(x);
18+
19+
})
20+
};
21+
}));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('x')) :
3+
typeof define === 'function' && define.amd ? define(['x'], factory) :
4+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.x));
5+
})(this, (function (x$1) { 'use strict';
6+
7+
var x = /*#__PURE__*/Object.freeze({
8+
__proto__: null,
9+
"00": x$1["00"],
10+
"9007199254740993": x$1["9007199254740993"]
11+
});
12+
13+
console.log(x);
14+
15+
}));
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as x from './x';
2+
console.log(x);

test/form/samples/index-key/x.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { '00', '9007199254740993' } from 'x';

0 commit comments

Comments
 (0)