-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
@babel/plugin-proposal-import-attributes-to-assertions
- Loading branch information
1 parent
71bbfa6
commit 83b0f65
Showing
13 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-import-attributes-to-assertions/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
test | ||
*.log |
19 changes: 19 additions & 0 deletions
19
packages/babel-plugin-proposal-import-attributes-to-assertions/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# @babel/plugin-proposal-import-attributes-to-assertions | ||
|
||
> Transform optional chaining operators to workaround https://crbug.com/v8/11558 | ||
See our website [@babel/plugin-proposal-import-attributes-to-assertions](https://babeljs.io/docs/en/babel-plugin-proposal-import-attributes-to-assertions) for more information. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```sh | ||
npm install --save-dev @babel/plugin-proposal-import-attributes-to-assertions | ||
``` | ||
|
||
or using yarn: | ||
|
||
```sh | ||
yarn add @babel/plugin-proposal-import-attributes-to-assertions --dev | ||
``` |
52 changes: 52 additions & 0 deletions
52
packages/babel-plugin-proposal-import-attributes-to-assertions/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@babel/plugin-proposal-import-attributes-to-assertions", | ||
"version": "7.21.8", | ||
"description": "Transform the Import Attributes proposal (`import ... from '...' with { ... }`) to the previous version known as Import Assertions (`import ... from '...' assert { ... }`).", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/babel/babel.git", | ||
"directory": "packages/babel-plugin-proposal-import-attributes-to-assertions" | ||
}, | ||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-import-attributes-to-assertions", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./lib/index.js", | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"keywords": [ | ||
"babel-plugin", | ||
"import", | ||
"attributes", | ||
"assertions", | ||
"proposal", | ||
"stage-3" | ||
], | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "workspace:^", | ||
"@babel/plugin-syntax-import-attributes": "workspace:^" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.22.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "workspace:^", | ||
"@babel/helper-plugin-test-runner": "workspace:^" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"type": "commonjs", | ||
"conditions": { | ||
"USE_ESM": [ | ||
{ | ||
"type": "module" | ||
}, | ||
null | ||
] | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/babel-plugin-proposal-import-attributes-to-assertions/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { declare } from "@babel/helper-plugin-utils"; | ||
import type { NodePath } from "@babel/traverse"; | ||
import type * as t from "@babel/types"; | ||
import syntaxImportAttributes from "@babel/plugin-syntax-import-attributes"; | ||
|
||
export default declare(api => { | ||
api.assertVersion(7); | ||
|
||
return { | ||
name: "proposal-import-attributes-to-assertions", | ||
|
||
inherits: syntaxImportAttributes, | ||
|
||
manipulateOptions({ generatorOpts }) { | ||
generatorOpts.importAttributesKeyword = "assert"; | ||
}, | ||
|
||
visitor: { | ||
"ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration"( | ||
path: NodePath< | ||
| t.ImportDeclaration | ||
| t.ExportNamedDeclaration | ||
| t.ExportAllDeclaration | ||
>, | ||
) { | ||
const { node } = path; | ||
if (!node.attributes) return; | ||
node.assertions = node.attributes; | ||
node.attributes = null; | ||
}, | ||
}, | ||
}; | ||
}); |
2 changes: 2 additions & 0 deletions
2
...abel-plugin-proposal-import-attributes-to-assertions/test/fixtures/basic/exports/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { a } from "a" with { type: "json" }; | ||
export * as ns from "c" with { type: "json" }; |
2 changes: 2 additions & 0 deletions
2
...el-plugin-proposal-import-attributes-to-assertions/test/fixtures/basic/exports/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { a } from "a" assert { type: "json" }; | ||
export * as ns from "c" assert { type: "json" }; |
4 changes: 4 additions & 0 deletions
4
...abel-plugin-proposal-import-attributes-to-assertions/test/fixtures/basic/imports/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { a } from "a" with { type: "json" }; | ||
import b from "b" with { type: "json" }; | ||
import * as ns from "c" with { type: "json" }; | ||
import "d" with { type: "json" }; |
4 changes: 4 additions & 0 deletions
4
...el-plugin-proposal-import-attributes-to-assertions/test/fixtures/basic/imports/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { a } from "a" assert { type: "json" }; | ||
import b from "b" assert { type: "json" }; | ||
import * as ns from "c" assert { type: "json" }; | ||
import "d" assert { type: "json" }; |
4 changes: 4 additions & 0 deletions
4
packages/babel-plugin-proposal-import-attributes-to-assertions/test/fixtures/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"sourceType": "module", | ||
"plugins": ["proposal-import-attributes-to-assertions"] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-import-attributes-to-assertions/test/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import runner from "@babel/helper-plugin-test-runner"; | ||
|
||
runner(import.meta.url); |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-proposal-import-attributes-to-assertions/test/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "type": "module" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters