Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create @babel/plugin-proposal-import-attributes-to-assertions #15620

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,3 @@
src
test
*.log
@@ -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
```
@@ -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
]
}
}
@@ -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;
},
},
};
});
@@ -0,0 +1,2 @@
export { a } from "a" with { type: "json" };
export * as ns from "c" with { type: "json" };
@@ -0,0 +1,2 @@
export { a } from "a" assert { type: "json" };
export * as ns from "c" assert { type: "json" };
@@ -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" };
@@ -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" };
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["proposal-import-attributes-to-assertions"]
}
@@ -0,0 +1,3 @@
import runner from "@babel/helper-plugin-test-runner";

runner(import.meta.url);
@@ -0,0 +1 @@
{ "type": "module" }
4 changes: 4 additions & 0 deletions tsconfig.json
Expand Up @@ -54,6 +54,7 @@
"./packages/babel-plugin-proposal-export-namespace-from/src/**/*.ts",
"./packages/babel-plugin-proposal-function-bind/src/**/*.ts",
"./packages/babel-plugin-proposal-function-sent/src/**/*.ts",
"./packages/babel-plugin-proposal-import-attributes-to-assertions/src/**/*.ts",
"./packages/babel-plugin-proposal-json-strings/src/**/*.ts",
"./packages/babel-plugin-proposal-logical-assignment-operators/src/**/*.ts",
"./packages/babel-plugin-proposal-nullish-coalescing-operator/src/**/*.ts",
Expand Down Expand Up @@ -329,6 +330,9 @@
"@babel/plugin-proposal-function-sent": [
"./packages/babel-plugin-proposal-function-sent/src"
],
"@babel/plugin-proposal-import-attributes-to-assertions": [
"./packages/babel-plugin-proposal-import-attributes-to-assertions/src"
],
"@babel/plugin-proposal-json-strings": [
"./packages/babel-plugin-proposal-json-strings/src"
],
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Expand Up @@ -1473,6 +1473,19 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/plugin-proposal-import-attributes-to-assertions@workspace:packages/babel-plugin-proposal-import-attributes-to-assertions":
version: 0.0.0-use.local
resolution: "@babel/plugin-proposal-import-attributes-to-assertions@workspace:packages/babel-plugin-proposal-import-attributes-to-assertions"
dependencies:
"@babel/core": "workspace:^"
"@babel/helper-plugin-test-runner": "workspace:^"
"@babel/helper-plugin-utils": "workspace:^"
"@babel/plugin-syntax-import-attributes": "workspace:^"
peerDependencies:
"@babel/core": ^7.22.0
languageName: unknown
linkType: soft

"@babel/plugin-proposal-json-strings@npm:^7.18.6":
version: 7.18.6
resolution: "@babel/plugin-proposal-json-strings@npm:7.18.6"
Expand Down