Skip to content

Commit 35fb91c

Browse files
authored
Merge pull request #85 from evcohen/stop-throwing-when-unknown-ast-nodes-are-encountered
Stop throwing errors when unknown AST nodes are encountered
2 parents a902df5 + 2ba4f2b commit 35fb91c

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

__tests__/src/getPropLiteralValue-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ describe('getLiteralPropValue', () => {
1919
assert.equal(expected, actual);
2020
});
2121

22-
it('should throw error when trying to get value from unknown node type', () => {
22+
it('should not throw error when trying to get value from unknown node type', () => {
2323
const prop = {
2424
type: 'JSXAttribute',
2525
value: {
2626
type: 'JSXExpressionContainer',
2727
},
2828
};
2929

30-
assert.throws(() => {
30+
assert.doesNotThrow(() => {
3131
getLiteralPropValue(prop);
3232
}, Error);
33+
34+
assert.equal(null, getLiteralPropValue(prop));
3335
});
3436

3537
describe('Null', () => {

__tests__/src/getPropValue-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ describe('getPropValue', () => {
3232
},
3333
};
3434

35-
assert.throws(() => {
35+
assert.doesNotThrow(() => {
3636
getPropValue(prop);
3737
}, Error);
38+
39+
assert.equal(null, getPropValue(prop));
3840
});
3941

4042
describe('Null', () => {

src/values/expressions/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ export default function extract(value) {
8080
}
8181

8282
if (TYPES[type] === undefined) {
83-
throw new Error(errorMessage(type));
83+
// eslint-disable-next-line no-console
84+
console.error(errorMessage(type));
85+
return null;
8486
}
8587

8688
return TYPES[type](expression);
@@ -145,7 +147,9 @@ export function extractLiteral(value) {
145147
const { type } = expression;
146148

147149
if (LITERAL_TYPES[type] === undefined) {
148-
throw new Error(errorMessage(type));
150+
// eslint-disable-next-line no-console
151+
console.error(errorMessage(type));
152+
return null;
149153
}
150154

151155
return LITERAL_TYPES[type](expression);

0 commit comments

Comments
 (0)