Skip to content

Commit 3106129

Browse files
committed
Fix code coverage
1 parent f67529f commit 3106129

File tree

10 files changed

+36
-32
lines changed

10 files changed

+36
-32
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"watch": "node scripts/watch.cjs",
4141
"prepare": "npm run compile-modules && npm run esm-to-cjs",
4242
"prepack": "npm run lint && npm run test && npm run test:cjs && npm run bundle-and-test",
43-
"coverage": "c8 --exclude src/lang/build.js --exclude src/lang/parse.js --reporter=lcovonly npm test"
43+
"coverage": "c8 --exclude src/lang/build.js --exclude src/lang/parse.js --exclude test --reporter=lcovonly npm test"
4444
},
4545
"dependencies": {
4646
"@discoveryjs/natural-compare": "^1.0.0"

src/lang/compile.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default function compile(ast, tolerant = false, suggestions = null) {
109109
if (nodes.has(node.type)) {
110110
nodes.get(node.type)(node, ctx, relatedNode);
111111
} else {
112-
throw new Error('Unknown node type `' + node.type + '`');
112+
throw new Error('Unknown node type "' + node.type + '"');
113113
}
114114

115115
if (spName) {
@@ -183,11 +183,6 @@ export default function compile(ast, tolerant = false, suggestions = null) {
183183
},
184184
put: chunk => buffer.push(chunk),
185185
node: walk,
186-
nodeOrNothing(node, relatedNode) {
187-
if (node) {
188-
walk(node, relatedNode);
189-
}
190-
},
191186
nodeOrCurrent(node, relatedNode) {
192187
walk(node || { type: 'Current' }, relatedNode);
193188
},

src/lang/stringify.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ function isSimpleGetPropertyQuery(node) {
55
return false;
66
}
77

8-
if (node.value && node.value.type !== 'Current') {
9-
return false;
10-
}
11-
12-
if (node.property.type !== 'Identifier') {
13-
return false;
14-
}
15-
168
return true;
179
}
1810

@@ -21,10 +13,6 @@ function isSimpleMethodCallQuery(node) {
2113
return false;
2214
}
2315

24-
if (node.value && node.value.type !== 'Current') {
25-
return false;
26-
}
27-
2816
return true;
2917
}
3018

@@ -33,7 +21,7 @@ export default function stringify(ast) {
3321
if (nodes.has(node.type)) {
3422
nodes.get(node.type)(node, ctx);
3523
} else {
36-
throw new Error('Unknown node type `' + node.type + '`');
24+
throw new Error('Unknown node type "' + node.type + '"');
3725
}
3826
}
3927

src/lang/suggest.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ function getSuggestRanges(from, to, input, commentRanges, noSuggestOnEofPos) {
3838
continue;
3939
}
4040

41-
if (commentFrom === from) {
42-
ranges.push(from, from);
43-
} else {
44-
ranges.push(from, commentFrom);
45-
}
46-
41+
ranges.push(from, commentFrom);
4742
from = commentTo;
4843
}
4944

src/lang/walk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function walk(ast, options) {
77
nodes.get(node.type)(node, ctx);
88
leave(node);
99
} else {
10-
throw new Error('Unknown node type `' + node.type + '`');
10+
throw new Error('Unknown node type "' + node.type + '"');
1111
}
1212
}
1313

test/helpers/all-syntax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export default [
99
'.({foo:a|b,bar:a|$x;y})',
1010
'.map(=>$["abc"] or $[abc] or $[])',
1111
'.map().().[]..()..a..a()[]',
12-
'.map([foo,$.foo,method(),$.method(),.(),$.(),.[],$.[],..(),..a,..a(),$..(),$..a,$..a()])',
12+
'.map([foo,$.foo,method(),$.method(),.(),$.(),.[],$.[],..(),..a,..a(),..$a(),$..(),$..a,$..a(),..($),..($+[]),..(a() or b())])',
1313
'.reduce(=>$$+$)'
1414
].join('');

test/method-sort.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ describe('sort()', () => {
142142
});
143143

144144
describe('mixed value types', () => {
145+
const fn = () => {};
145146
const data = [
146147
true,
147148
1,
@@ -156,7 +157,8 @@ describe('sort()', () => {
156157
{ b: 1 },
157158
undefined,
158159
NaN,
159-
Infinity
160+
Infinity,
161+
fn
160162
];
161163

162164
it('asc', () => {
@@ -176,6 +178,7 @@ describe('sort()', () => {
176178
null,
177179
{ c: 1 },
178180
{ b: 1 },
181+
fn,
179182
undefined
180183
])
181184
);
@@ -184,6 +187,7 @@ describe('sort()', () => {
184187
assert.deepEqual(
185188
escapeNaN(query('sort($ desc)')([...data])),
186189
escapeNaN([
190+
fn,
187191
{ c: 1 },
188192
{ b: 1 },
189193
null,

test/syntax-compile.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import assert from 'assert';
2-
import query from 'jora';
2+
import jora from 'jora';
33

4+
const { syntax: { parse, compile } } = jora;
45
const match = assert.match || ((str, rx) => assert(rx.test(str), `${str} doesn't match to ${rx}`));
56

67
describe('syntax/compile', () => {
78
it('compilation error', () => {
89
assert.throws(
910
() => {
10-
const { ast } = query.syntax.parse('foo()');
11+
const { ast } = parse('foo()');
1112
ast.body.method.reference.name = ','; // break AST for a compilation error simulation
12-
query.syntax.compile(ast);
13+
compile(ast);
1314
},
1415
(error) => {
1516
match(error.compiledSource, /data,context/);
@@ -20,4 +21,11 @@ describe('syntax/compile', () => {
2021
}
2122
);
2223
});
24+
25+
it('unknown node type', () => {
26+
assert.throws(
27+
() => compile({ type: 'Foo' }),
28+
/Unknown node type "Foo"/
29+
);
30+
});
2331
});

test/syntax-stringify.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ describe('syntax/stringify', () => {
1010

1111
assert.equal(actual, allSyntax);
1212
});
13+
14+
it('unknown node type', () => {
15+
assert.throws(
16+
() => stringify({ type: 'Foo' }),
17+
/Unknown node type "Foo"/
18+
);
19+
});
1320
});

test/syntax-walk.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,11 @@ describe('syntax/walk', () => {
5353

5454
assert.deepEqual(actual.sort(), expected.sort());
5555
});
56+
57+
it('unknown node type', () => {
58+
assert.throws(
59+
() => walk({ type: 'Foo' }),
60+
/Unknown node type "Foo"/
61+
);
62+
});
5663
});

0 commit comments

Comments
 (0)