Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid strict-mode syntax with hexadecimal #22

Merged
merged 3 commits into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# eslintignore

# TODO: fix
index.js
43 changes: 43 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"root": true,
"extends": "@ljharb",
"rules": {
"indent": [2, 4],
"strict": 1,
},
"globals": {
"BigInt": false,
},
"overrides": [
{
"files": ["test/**", "test-*", "example/**"],
"rules": {
"array-bracket-newline": 0,
"max-params": 0,
"max-statements": 0,
"max-statements-per-line": 0,
"no-magic-numbers": 0,
"object-curly-newline": 0,
"sort-keys": 0,
},
},
{
"files": ["example/**"],
"rules": {
"no-console": 0,
},
},
{
"files": ["test/browser/**"],
"env": {
"browser": true,
},
},
{
"files": ["test/bigint*"],
"rules": {
"new-cap": [2, { "capIsNewExceptions": ["BigInt"] }],
},
},
],
}
102 changes: 99 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ language: node_js
os:
- linux
node_js:
- "10.0"
- "12.7"
- "11.15"
- "10.16"
- "9.11"
- "8.11"
- "8.16"
- "7.10"
- "6.14"
- "6.17"
- "5.12"
- "4.9"
- "iojs-v3.3"
Expand Down Expand Up @@ -35,8 +37,86 @@ matrix:
include:
- node_js: "10.0"
env: BIGINT=true
- node_js: "lts/*"
env: PRETEST=true
- node_js: "node"
env: COVERAGE=true
- node_js: "12.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "12.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "12.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "12.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "12.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "12.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "12.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.14"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.13"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.12"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.11"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "11.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.15"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.14"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.13"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.12"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.11"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.9"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.8"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.7"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.6"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.5"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.4"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.3"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.2"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.1"
env: TEST=true ALLOW_FAILURE=true
- node_js: "10.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.9"
Expand All @@ -59,6 +139,16 @@ matrix:
env: TEST=true ALLOW_FAILURE=true
- node_js: "9.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.15"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.14"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.13"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.12"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.11"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.10"
env: TEST=true ALLOW_FAILURE=true
- node_js: "8.9"
Expand Down Expand Up @@ -101,6 +191,12 @@ matrix:
env: TEST=true ALLOW_FAILURE=true
- node_js: "7.0"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.16"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.15"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.14"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.13"
env: TEST=true ALLOW_FAILURE=true
- node_js: "6.12"
Expand Down
12 changes: 8 additions & 4 deletions example/all.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
'use strict';

var inspect = require('../');
var Buffer = require('safer-buffer').Buffer;

var holes = [ 'a', 'b' ];
holes[4] = 'e', holes[6] = 'g';
var holes = ['a', 'b'];
holes[4] = 'e';
holes[6] = 'g';

var obj = {
a: 1,
b: [ 3, 4, undefined, null ],
b: [3, 4, undefined, null],
c: undefined,
d: null,
e: {
regex: /^x/i,
buf: Buffer.from('abc'),
holes: holes
},
now: new Date
now: new Date()
};
obj.self = obj;
console.log(inspect(obj));
4 changes: 3 additions & 1 deletion example/circular.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';

var inspect = require('../');
var obj = { a: 1, b: [3,4] };
var obj = { a: 1, b: [3, 4] };
obj.c = obj;
console.log(inspect(obj));
4 changes: 3 additions & 1 deletion example/fn.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var inspect = require('../');
var obj = [ 1, 2, function f (n) { return n + 5 }, 4 ];
var obj = [1, 2, function f(n) { return n + 5; }, 4];
console.log(inspect(obj));
5 changes: 4 additions & 1 deletion example/inspect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';

/* eslint-env browser */
var inspect = require('../');

var d = document.createElement('div');
d.setAttribute('id', 'beep');
d.innerHTML = '<b>wooo</b><i>iiiii</i>';

console.log(inspect([ d, { a: 3, b : 4, c: [5,6,[7,[8,[9]]]] } ]));
console.log(inspect([d, { a: 3, b: 4, c: [5, 6, [7, [8, [9]]]] }]));
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
"description": "string representations of objects in node and the browser",
"main": "index.js",
"devDependencies": {
"@ljharb/eslint-config": "^13.1.1",
"core-js": "^2.5.5",
"eslint": "^5.16.0",
"nyc": "^10.3.2",
"tape": "^4.9.0"
},
"scripts": {
"pretest": "npm run lint",
"lint": "eslint .",
"test": "npm run tests-only",
"posttest": "npm run test:bigint",
"pretests-only": "node test-core-js",
Expand Down
39 changes: 20 additions & 19 deletions test/bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ var inspect = require('../');
var test = require('tape');

test('bigint', { skip: typeof BigInt === 'undefined' }, function (t) {
t.test('primitives', function (st) {
st.plan(3);
t.test('primitives', function (st) {
st.plan(3);

st.equal(inspect(BigInt(-256)), '-256n');
st.equal(inspect(BigInt(0)), '0n');
st.equal(inspect(BigInt(256)), '256n');
});
st.equal(inspect(BigInt(-256)), '-256n');
st.equal(inspect(BigInt(0)), '0n');
st.equal(inspect(BigInt(256)), '256n');
});

t.test('objects', function (st) {
st.plan(3);
t.test('objects', function (st) {
st.plan(3);

st.equal(inspect(Object(BigInt(-256))), 'Object(-256n)');
st.equal(inspect(Object(BigInt(0))), 'Object(0n)');
st.equal(inspect(Object(BigInt(256))), 'Object(256n)');
});
st.equal(inspect(Object(BigInt(-256))), 'Object(-256n)');
st.equal(inspect(Object(BigInt(0))), 'Object(0n)');
st.equal(inspect(Object(BigInt(256))), 'Object(256n)');
});

t.test('syntactic primitives', function (st) {
st.plan(3);
t.test('syntactic primitives', function (st) {
st.plan(3);

st.equal(inspect(Function('return -256n')()), '-256n');
st.equal(inspect(Function('return 0n')()), '0n');
st.equal(inspect(Function('return 256n')()), '256n');
});
/* eslint-disable no-new-func */
st.equal(inspect(Function('return -256n')()), '-256n');
st.equal(inspect(Function('return 0n')()), '0n');
st.equal(inspect(Function('return 256n')()), '256n');
});

t.end();
t.end();
});
6 changes: 3 additions & 3 deletions test/browser/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ var test = require('tape');

test('dom element', function (t) {
t.plan(1);

var d = document.createElement('div');
d.setAttribute('id', 'beep');
d.innerHTML = '<b>wooo</b><i>iiiii</i>';

t.equal(
inspect([ d, { a: 3, b : 4, c: [5,6,[7,[8,[9]]]] } ]),
inspect([d, { a: 3, b: 4, c: [5, 6, [7, [8, [9]]]] }]),
'[ <div id="beep">...</div>, { a: 3, b: 4, c: [ 5, 6, [ 7, [ 8, [Object] ] ] ] } ]'
);
});
2 changes: 1 addition & 1 deletion test/circular.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var test = require('tape');

test('circular', function (t) {
t.plan(1);
var obj = { a: 1, b: [3,4] };
var obj = { a: 1, b: [3, 4] };
obj.c = obj;
t.equal(inspect(obj), '{ a: 1, b: [ 3, 4 ], c: [Circular] }');
});
2 changes: 1 addition & 1 deletion test/deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var test = require('tape');

test('deep', function (t) {
t.plan(2);
var obj = [ [ [ [ [ [ 500 ] ] ] ] ] ];
var obj = [[[[[[500]]]]]];
t.equal(inspect(obj), '[ [ [ [ [ [Object] ] ] ] ] ]');
t.equal(inspect(obj, { depth: 2 }), '[ [ [Object] ] ]');
});
24 changes: 12 additions & 12 deletions test/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ test('element', function (t) {
t.plan(3);
var elem = {
nodeName: 'div',
attributes: [ { name: 'class', value: 'row' } ],
getAttribute: function (key) {},
attributes: [{ name: 'class', value: 'row' }],
getAttribute: function (key) { return key; },
childNodes: []
};
var obj = [ 1, elem, 3 ];
var obj = [1, elem, 3];
t.deepEqual(inspect(obj), '[ 1, <div class="row"></div>, 3 ]');
t.deepEqual(inspect(obj, { quoteStyle: 'single' }), "[ 1, <div class='row'></div>, 3 ]");
t.deepEqual(inspect(obj, { quoteStyle: 'double' }), '[ 1, <div class="row"></div>, 3 ]');
});

test('element no attr', function (t) {
t.plan(1);
var elem = {
nodeName: 'div',
getAttribute: function (key) {},
getAttribute: function (key) { return key; },
childNodes: []
};
var obj = [ 1, elem, 3 ];
var obj = [1, elem, 3];
t.deepEqual(inspect(obj), '[ 1, <div></div>, 3 ]');
});

test('element with contents', function (t) {
t.plan(1);
var elem = {
nodeName: 'div',
getAttribute: function (key) {},
childNodes: [ { nodeName: 'b' } ]
getAttribute: function (key) { return key; },
childNodes: [{ nodeName: 'b' }]
};
var obj = [ 1, elem, 3 ];
var obj = [1, elem, 3];
t.deepEqual(inspect(obj), '[ 1, <div>...</div>, 3 ]');
});

Expand All @@ -45,9 +45,9 @@ test('element instance', function (t) {
this.attributes = attr;
};
global.HTMLElement.prototype.getAttribute = function () {};
var elem = new(global.HTMLElement)('div', []);
var obj = [ 1, elem, 3 ];

var elem = new global.HTMLElement('div', []);
var obj = [1, elem, 3];
t.deepEqual(inspect(obj), '[ 1, <div></div>, 3 ]');
global.HTMLElement = h;
});
Loading