acorn-import-assertions
Advanced tools
Comparing version 1.4.3 to 1.4.4
@@ -12,2 +12,4 @@ "use strict"; | ||
var _charcodes = require("charcodes"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -76,6 +78,14 @@ | ||
value: function readToken(code) { | ||
for (var i = 0; i < keyword.length; i++) { | ||
var i = 0; | ||
for (; i < keyword.length; i++) { | ||
if (this._codeAt(this.pos + i) !== keyword.charCodeAt(i)) { | ||
return _get(_getPrototypeOf(_class.prototype), "readToken", this).call(this, code); | ||
} | ||
} // ensure that the word is at the correct location | ||
// ie `assert{...` or `assert {...` | ||
if (this._codeAt(i) !== _charcodes.space && this._codeAt(i) !== _charcodes.leftCurlyBrace) { | ||
return _get(_getPrototypeOf(_class.prototype), "readToken", this).call(this, code); | ||
} | ||
@@ -82,0 +92,0 @@ |
{ | ||
"name": "acorn-import-assertions", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "Support for import assertions in acorn", | ||
@@ -29,3 +29,6 @@ "main": "lib/index.js", | ||
"url": "https://github.com/xtuc/acorn-import-assertions" | ||
}, | ||
"dependencies": { | ||
"charcodes": "^0.2.0" | ||
} | ||
} |
import { tokTypes as tt, TokenType } from "acorn"; | ||
import { space, leftCurlyBrace } from "charcodes"; | ||
@@ -20,7 +21,8 @@ const keyword = "assert"; | ||
} | ||
this.next() | ||
this.next(); | ||
} | ||
readToken(code) { | ||
for (let i = 0; i < keyword.length; i++) { | ||
let i = 0; | ||
for (; i < keyword.length; i++) { | ||
if (this._codeAt(this.pos + i) !== keyword.charCodeAt(i)) { | ||
@@ -31,2 +33,8 @@ return super.readToken(code); | ||
// ensure that the word is at the correct location | ||
// ie `assert{...` or `assert {...` | ||
if (this._codeAt(i) !== space && this._codeAt(i) !== leftCurlyBrace) { | ||
return super.readToken(code); | ||
} | ||
this.pos += keyword.length; | ||
@@ -37,6 +45,6 @@ return this.finishToken(this.assertToken); | ||
parseDynamicImport(node) { | ||
this.next() // skip `(` | ||
this.next(); // skip `(` | ||
// Parse node.source. | ||
node.source = this.parseMaybeAssign() | ||
node.source = this.parseMaybeAssign(); | ||
@@ -51,3 +59,3 @@ if (this.eat(tt.comma)) { | ||
} | ||
return this.finishNode(node, "ImportExpression") | ||
return this.finishNode(node, "ImportExpression"); | ||
} | ||
@@ -109,3 +117,3 @@ | ||
if (node.key.name !== "type") { | ||
this.raise(this.pos, "The only accepted import assertion is `type`") | ||
this.raise(this.pos, "The only accepted import assertion is `type`"); | ||
} | ||
@@ -116,3 +124,3 @@ // check if we already have an entry for an attribute | ||
if (attrNames.has(node.key.name)) { | ||
this.raise(this.pos, "Duplicated key in assertions") | ||
this.raise(this.pos, "Duplicated key in assertions"); | ||
} | ||
@@ -122,3 +130,6 @@ attrNames.add(node.key.name); | ||
if (this.type !== tt.string) { | ||
this.raise(this.pos, "Only string is supported as an assertion value") | ||
this.raise( | ||
this.pos, | ||
"Only string is supported as an assertion value" | ||
); | ||
} | ||
@@ -125,0 +136,0 @@ |
37058
26
1392
2
+ Addedcharcodes@^0.2.0
+ Addedcharcodes@0.2.0(transitive)