Skip to content

Commit

Permalink
fix: always assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Mar 28, 2024
1 parent b7a410c commit ed56cec
Show file tree
Hide file tree
Showing 11 changed files with 1,169 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ function pluginImpl(options, Parser) {
node.source = this.parseExprAtom();

if (this._matchKeywordToken()) {
const property = this._getProperty();
this.next();
const attributes = this.parseImportAttributes();
if (attributes) {
node[this._getProperty()] = attributes;
node[property] = attributes;
}
}

Expand Down Expand Up @@ -187,10 +188,11 @@ function pluginImpl(options, Parser) {
node.source = this.parseExprAtom();

if (this._matchKeywordToken()) {
const property = this._getProperty();
this.next();
const attributes = this.parseImportAttributes();
if (attributes) {
node[this._getProperty()] = attributes;
node[property] = attributes;
}
}
} else {
Expand Down Expand Up @@ -224,10 +226,11 @@ function pluginImpl(options, Parser) {
}

if (this._matchKeywordToken()) {
const property = this._getProperty();
this.next();
const attributes = this.parseImportAttributes();
if (attributes) {
node[this._getProperty()] = attributes;
node[property] = attributes;
}
}
this.semicolon();
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/assertions-type/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import json from "./foo.json" assert { type: "json" };
165 changes: 165 additions & 0 deletions test/fixtures/assertions-type/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"type": "Program",
"start": 0,
"end": 55,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
},
"range": [
0,
55
],
"body": [
{
"type": "ImportDeclaration",
"start": 0,
"end": 54,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 54
}
},
"range": [
0,
54
],
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start": 7,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 11
}
},
"range": [
7,
11
],
"local": {
"type": "Identifier",
"start": 7,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 11
}
},
"range": [
7,
11
],
"name": "json"
}
}
],
"source": {
"type": "Literal",
"start": 17,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 29
}
},
"range": [
17,
29
],
"value": "./foo.json",
"raw": "\"./foo.json\""
},
"assertions": [
{
"type": "ImportAttribute",
"start": 39,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 39
},
"end": {
"line": 1,
"column": 51
}
},
"range": [
39,
51
],
"key": {
"type": "Identifier",
"start": 39,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 39
},
"end": {
"line": 1,
"column": 43
}
},
"range": [
39,
43
],
"name": "type"
},
"value": {
"type": "Literal",
"start": 45,
"end": 51,
"loc": {
"start": {
"line": 1,
"column": 45
},
"end": {
"line": 1,
"column": 51
}
},
"range": [
45,
51
],
"value": "json",
"raw": "\"json\""
}
}
]
}
],
"sourceType": "module"
}
2 changes: 2 additions & 0 deletions test/fixtures/attributes-assertions-dynamic-import/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import("./dynamic-package.json", { assert: { type: "json" } });
import("./dynamic-package-with.json", { with: { type: "json" } });
Loading

0 comments on commit ed56cec

Please sign in to comment.