From 8379ae3bb63b9e3144d2eeee760c449e37e1c82f Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Sun, 11 Aug 2019 19:45:16 +0200 Subject: [PATCH] Align with estree/estree#198 --- lib/assets/JavaScript.js | 28 +++++++++++------------- lib/relations/JavaScriptDynamicImport.js | 4 ++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/assets/JavaScript.js b/lib/assets/JavaScript.js index c2b48765a3..ea3c241216 100644 --- a/lib/assets/JavaScript.js +++ b/lib/assets/JavaScript.js @@ -421,7 +421,19 @@ class JavaScript extends Text { that.strict = true; } - if (node.type === 'CallExpression') { + if ( + node.type === 'ImportExpression' && + node.source.type === 'Literal' && + typeof node.source.value === 'string' + ) { + if (isImportUrl(node.source.value)) { + outgoingRelations.push({ + type: 'JavaScriptDynamicImport', + node, + href: node.source.value + }); + } + } else if (node.type === 'CallExpression') { const parentParentNode = stack[stack.length - 3]; if ( @@ -537,20 +549,6 @@ class JavaScript extends Text { }); } } - } else if ( - node.type === 'CallExpression' && - node.callee.type === 'Import' && - node.arguments[0] && - node.arguments[0].type === 'Literal' && - typeof node.arguments[0].value === 'string' - ) { - if (isImportUrl(node.arguments[0].value)) { - outgoingRelations.push({ - type: 'JavaScriptDynamicImport', - node, - href: node.arguments[0].value - }); - } } } else if ( node.type === 'NewExpression' && diff --git a/lib/relations/JavaScriptDynamicImport.js b/lib/relations/JavaScriptDynamicImport.js index fabcc4e0d8..bd447be344 100644 --- a/lib/relations/JavaScriptDynamicImport.js +++ b/lib/relations/JavaScriptDynamicImport.js @@ -2,11 +2,11 @@ const Relation = require('./Relation'); class JavaScriptDynamicImport extends Relation { get href() { - return this.node.arguments[0].value; + return this.node.source.value; } set href(href) { - this.node.arguments[0].value = href; + this.node.source.value = href; } attach(position, adjacentRelation) {