-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Import bytes proposal #17817
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
Open
nicolo-ribaudo
wants to merge
1
commit into
babel:main
Choose a base branch
from
nicolo-ribaudo:import-bytes-proposal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Import bytes proposal #17817
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
| /* @minVersion 8.0.0-rc.2 */ | ||
|
|
||
| declare global { | ||
| interface ArrayBuffer { | ||
| transferToImmutable?(): ArrayBuffer; | ||
| } | ||
| } | ||
|
|
||
| export default function _immutableUint8Array( | ||
| u8orNodeBuffer: Uint8Array<ArrayBuffer>, | ||
| ) { | ||
| var buf = u8orNodeBuffer.buffer; | ||
| return new Uint8Array( | ||
| buf.transferToImmutable ? buf.transferToImmutable() : buf, | ||
| ); | ||
| } |
This file contains hidden or 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,5 @@ | ||
| src | ||
| test | ||
| *.log | ||
| tsconfig.json | ||
| tsconfig.tsbuildinfo |
This file contains hidden or 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-bytes-modules | ||
|
|
||
| > Transform bytes modules imports (`import '...' with { type: 'bytes' }`) to work in browsers and Node.js. | ||
|
|
||
| See our website [@babel/plugin-proposal-bytes-modules](https://babeljs.io/docs/babel-plugin-proposal-bytes-modules) for more information. | ||
|
|
||
| ## Install | ||
|
|
||
| Using npm: | ||
|
|
||
| ```sh | ||
| npm install --save-dev @babel/plugin-proposal-bytes-modules | ||
| ``` | ||
|
|
||
| or using yarn: | ||
|
|
||
| ```sh | ||
| yarn add @babel/plugin-proposal-bytes-modules --dev | ||
| ``` |
This file contains hidden or 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,51 @@ | ||
| { | ||
| "name": "@babel/plugin-proposal-bytes-modules", | ||
| "version": "8.0.0-rc.2", | ||
| "description": "Transform bytes modules imports (`import '...' with { type: 'bytes' }`) to work in browsers and Node.js.", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/babel/babel.git", | ||
| "directory": "packages/babel-plugin-proposal-bytes-modules" | ||
| }, | ||
| "homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-bytes-modules", | ||
| "license": "MIT", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "main": "./lib/index.js", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./lib/index.d.ts", | ||
| "default": "./lib/index.js" | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "keywords": [ | ||
| "babel-plugin", | ||
| "import", | ||
| "source", | ||
| "phase", | ||
| "wasm", | ||
| "WebAssembly", | ||
| "assertions", | ||
| "proposal", | ||
| "stage-3" | ||
| ], | ||
| "dependencies": { | ||
| "@babel/helper-import-to-platform-api": "workspace:^", | ||
| "@babel/helper-plugin-utils": "workspace:^" | ||
| }, | ||
| "peerDependencies": { | ||
| "@babel/core": "workspace:^" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/core": "workspace:^", | ||
| "@babel/helper-plugin-test-runner": "workspace:^", | ||
| "babel-plugin-polyfill-corejs3": "^0.14.0" | ||
| }, | ||
| "engines": { | ||
| "node": "^20.19.0 || >=22.12.0" | ||
| }, | ||
| "author": "The Babel Team (https://babel.dev/team)", | ||
| "type": "module" | ||
| } |
117 changes: 117 additions & 0 deletions
117
packages/babel-plugin-proposal-bytes-modules/src/index.ts
This file contains hidden or 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,117 @@ | ||
| import { declare } from "@babel/helper-plugin-utils"; | ||
| import type { types as t, File } from "@babel/core"; | ||
| import { | ||
| importToPlatformApi, | ||
| buildParallelStaticImports, | ||
| type Pieces, | ||
| type Builders, | ||
| } from "@babel/helper-import-to-platform-api"; | ||
|
|
||
| export default declare(api => { | ||
| const { types: t, template } = api; | ||
| api.assertVersion(REQUIRED_VERSION("^8.0.0")); | ||
|
|
||
| const targets = api.targets(); | ||
|
|
||
| let helperESM: Builders; | ||
| let helperCJS: Builders; | ||
|
|
||
| const transformers: Pieces = { | ||
| webFetch: (fetch, file) => | ||
| template.expression.ast` | ||
| ${fetch}.then(r => r.bytes()).then(${file.addHelper("immutableUint8Array")}) | ||
| `, | ||
| nodeFsSync: (buf, file) => | ||
| t.callExpression(file.addHelper("immutableUint8Array"), [buf]), | ||
| nodeFsAsync: file => file.addHelper("immutableUint8Array"), | ||
| }; | ||
|
|
||
| const getHelper = (file: File) => { | ||
| const modules = file.get("@babel/plugin-transform-modules-*"); | ||
| if (modules === "commonjs") { | ||
| return (helperCJS ??= importToPlatformApi(targets, transformers, true)); | ||
| } | ||
| if (modules == null) { | ||
| return (helperESM ??= importToPlatformApi(targets, transformers, false)); | ||
| } | ||
| throw new Error( | ||
| `@babel/plugin-proposal-bytes-modules can only be used when not ` + | ||
| `compiling modules, or when compiling them to CommonJS.`, | ||
| ); | ||
| }; | ||
|
|
||
| function getAttributeKey({ key }: t.ImportAttribute): string { | ||
| return t.isIdentifier(key) ? key.name : key.value; | ||
| } | ||
|
|
||
| function hasTypeBytes(attributes: t.ImportAttribute[]) { | ||
| return !!attributes?.some( | ||
| attr => getAttributeKey(attr) === "type" && attr.value.value === "bytes", | ||
| ); | ||
| } | ||
|
|
||
| return { | ||
| name: "proposal-bytes-modules", | ||
|
|
||
| visitor: { | ||
| Program(path) { | ||
| if (path.node.sourceType !== "module") return; | ||
|
|
||
| const helper = getHelper(this.file); | ||
|
|
||
| const data = []; | ||
| for (const decl of path.get("body")) { | ||
| if (!decl.isImportDeclaration()) continue; | ||
| const attributes = decl.node.attributes || undefined; | ||
| if (!hasTypeBytes(attributes)) continue; | ||
|
|
||
| if (decl.node.phase != null) { | ||
| throw decl.buildCodeFrameError( | ||
| "Bytes modules do not support phase modifiers.", | ||
| ); | ||
| } | ||
| if (attributes.length > 1) { | ||
| const paths = decl.get("attributes"); | ||
| const index = getAttributeKey(attributes[0]) === "type" ? 1 : 0; | ||
| throw paths[index].buildCodeFrameError( | ||
| "Unknown attribute for bytes modules.", | ||
| ); | ||
| } | ||
|
|
||
| let id: t.Identifier; | ||
| let needsNS = false; | ||
| for (const specifier of decl.get("specifiers")) { | ||
| if (specifier.isImportSpecifier()) { | ||
| throw specifier.buildCodeFrameError( | ||
| "Bytes modules do not support named imports.", | ||
| ); | ||
| } | ||
|
|
||
| id = specifier.node.local; | ||
| needsNS = specifier.isImportNamespaceSpecifier(); | ||
| } | ||
| id ??= path.scope.generateUidIdentifier("_"); | ||
|
|
||
| let fetch = helper.buildFetch(decl.node.source, this.file); | ||
|
|
||
| if (needsNS) { | ||
| if (helper.needsAwait) { | ||
| fetch = template.expression.ast` | ||
| ${fetch}.then(j => ({ default: j })) | ||
| `; | ||
| } else { | ||
| fetch = template.expression.ast`{ default: ${fetch} }`; | ||
| } | ||
| } | ||
|
|
||
| data.push({ id, fetch }); | ||
| decl.remove(); | ||
| } | ||
| if (data.length === 0) return; | ||
|
|
||
| const decl = buildParallelStaticImports(data, helper.needsAwait); | ||
| if (decl) path.unshiftContainer("body", decl); | ||
| }, | ||
| }, | ||
| }; | ||
| }); |
1 change: 1 addition & 0 deletions
1
...ytes-modules/test/fixtures/browser-and-node-esm/import-declaration-empty-targets/input.js
This file contains hidden or 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 @@ | ||
| import j from "./x" with { type: "bytes" }; |
4 changes: 4 additions & 0 deletions
4
...-modules/test/fixtures/browser-and-node-esm/import-declaration-empty-targets/options.json
This file contains hidden or 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", | ||
| "targets": [] | ||
| } |
2 changes: 2 additions & 0 deletions
2
...es-modules/test/fixtures/browser-and-node-esm/import-declaration-empty-targets/output.mjs
This file contains hidden or 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 @@ | ||
| const j = await (typeof process === "object" && process.versions?.node ? Promise.all([import("fs"), import("module")]).then(([fs, module]) => new Promise((a => (r, j) => fs.readFile(a, (e, d) => e ? j(e) : r(d)))(module.createRequire(import.meta.url).resolve("./x")))).then(_immutableUint8Array) : fetch(import.meta.resolve?.("./x") ?? new URL("./x", import.meta.url)).then(r => r.bytes()).then(_immutableUint8Array)); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } |
3 changes: 3 additions & 0 deletions
3
...sal-bytes-modules/test/fixtures/browser-and-node-esm/import-declaration-multiple/input.js
This file contains hidden or 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 j from "./x" with { type: "bytes" }; | ||
| someBody; | ||
| import j2 from "./x3" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
...l-bytes-modules/test/fixtures/browser-and-node-esm/import-declaration-multiple/output.mjs
This file contains hidden or 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 @@ | ||
| const [j, j2] = await Promise.all([typeof process === "object" && process.versions?.node ? import("fs").then(fs => fs.promises.readFile(new URL(import.meta.resolve("./x")))).then(_immutableUint8Array) : fetch(import.meta.resolve("./x")).then(r => r.bytes()).then(_immutableUint8Array), typeof process === "object" && process.versions?.node ? import("fs").then(fs => fs.promises.readFile(new URL(import.meta.resolve("./x3")))).then(_immutableUint8Array) : fetch(import.meta.resolve("./x3")).then(r => r.bytes()).then(_immutableUint8Array)]); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } | ||
| someBody; |
1 change: 1 addition & 0 deletions
1
...al-bytes-modules/test/fixtures/browser-and-node-esm/import-declaration-namespace/input.js
This file contains hidden or 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 @@ | ||
| import * as ns from "./x" with { type: "bytes" }; |
4 changes: 4 additions & 0 deletions
4
...-bytes-modules/test/fixtures/browser-and-node-esm/import-declaration-namespace/output.mjs
This file contains hidden or 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 @@ | ||
| const ns = await (typeof process === "object" && process.versions?.node ? import("fs").then(fs => fs.promises.readFile(new URL(import.meta.resolve("./x")))).then(_immutableUint8Array) : fetch(import.meta.resolve("./x")).then(r => r.bytes()).then(_immutableUint8Array)).then(j => ({ | ||
| default: j | ||
| })); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } |
1 change: 1 addition & 0 deletions
1
...gin-proposal-bytes-modules/test/fixtures/browser-and-node-esm/import-declaration/input.js
This file contains hidden or 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 @@ | ||
| import j from "./x" with { type: "bytes" }; |
2 changes: 2 additions & 0 deletions
2
...n-proposal-bytes-modules/test/fixtures/browser-and-node-esm/import-declaration/output.mjs
This file contains hidden or 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 @@ | ||
| const j = await (typeof process === "object" && process.versions?.node ? import("fs").then(fs => fs.promises.readFile(new URL(import.meta.resolve("./x")))).then(_immutableUint8Array) : fetch(import.meta.resolve("./x")).then(r => r.bytes()).then(_immutableUint8Array)); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } |
2 changes: 2 additions & 0 deletions
2
...ugin-proposal-bytes-modules/test/fixtures/browser-and-node-esm/import-expression/input.js
This file contains hidden or 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 @@ | ||
| // TODO: Not supported yet | ||
| let promise = import("./x", { with: { type: "bytes" } }); | ||
6 changes: 6 additions & 0 deletions
6
...in-proposal-bytes-modules/test/fixtures/browser-and-node-esm/import-expression/output.mjs
This file contains hidden or 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,6 @@ | ||
| // TODO: Not supported yet | ||
| let promise = import("./x", { | ||
| with: { | ||
| type: "bytes" | ||
| } | ||
| }); |
1 change: 1 addition & 0 deletions
1
...modules/test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-both/input.js
This file contains hidden or 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 @@ | ||
| import j from "./x" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
...les/test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-both/options.json
This file contains hidden or 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 @@ | ||
| { | ||
| "targets": { "firefox": "90", "node": "20.0" } | ||
| } |
2 changes: 2 additions & 0 deletions
2
...dules/test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-both/output.mjs
This file contains hidden or 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 @@ | ||
| const j = await (typeof process === "object" && process.versions?.node ? Promise.all([import("fs"), import("module")]).then(([fs, module]) => fs.promises.readFile(module.createRequire(import.meta.url).resolve("./x"))).then(_immutableUint8Array) : fetch(import.meta.resolve?.("./x") ?? new URL("./x", import.meta.url)).then(r => r.bytes()).then(_immutableUint8Array)); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } |
1 change: 1 addition & 0 deletions
1
...ules/test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-browser/input.js
This file contains hidden or 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 @@ | ||
| import j from "./x" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
.../test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-browser/options.json
This file contains hidden or 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 @@ | ||
| { | ||
| "targets": { "firefox": "90", "node": "20.6" } | ||
| } |
2 changes: 2 additions & 0 deletions
2
...es/test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-browser/output.mjs
This file contains hidden or 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 @@ | ||
| const j = await (typeof process === "object" && process.versions?.node ? import("fs").then(fs => fs.promises.readFile(new URL(import.meta.resolve("./x")))).then(_immutableUint8Array) : fetch(import.meta.resolve?.("./x") ?? new URL("./x", import.meta.url)).then(r => r.bytes()).then(_immutableUint8Array)); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } |
1 change: 1 addition & 0 deletions
1
...modules/test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-node/input.js
This file contains hidden or 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 @@ | ||
| import j from "./x" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
...les/test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-node/options.json
This file contains hidden or 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 @@ | ||
| { | ||
| "targets": { "firefox": "110", "node": "20.0" } | ||
| } |
2 changes: 2 additions & 0 deletions
2
...dules/test/fixtures/browser-and-node-esm/import-meta-resolve-fallback-for-node/output.mjs
This file contains hidden or 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 @@ | ||
| const j = await (typeof process === "object" && process.versions?.node ? Promise.all([import("fs"), import("module")]).then(([fs, module]) => fs.promises.readFile(module.createRequire(import.meta.url).resolve("./x"))).then(_immutableUint8Array) : fetch(import.meta.resolve("./x")).then(r => r.bytes()).then(_immutableUint8Array)); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } |
1 change: 1 addition & 0 deletions
1
...proposal-bytes-modules/test/fixtures/browser-and-node-esm/no-fs-promises-support/input.js
This file contains hidden or 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 @@ | ||
| import j from "./x" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
...osal-bytes-modules/test/fixtures/browser-and-node-esm/no-fs-promises-support/options.json
This file contains hidden or 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 @@ | ||
| { | ||
| "targets": { "firefox": "110", "node": "9.0" } | ||
| } |
2 changes: 2 additions & 0 deletions
2
...oposal-bytes-modules/test/fixtures/browser-and-node-esm/no-fs-promises-support/output.mjs
This file contains hidden or 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 @@ | ||
| const j = await (typeof process === "object" && process.versions?.node ? Promise.all([import("fs"), import("module")]).then(([fs, module]) => new Promise((a => (r, j) => fs.readFile(a, (e, d) => e ? j(e) : r(d)))(module.createRequire(import.meta.url).resolve("./x")))).then(_immutableUint8Array) : fetch(import.meta.resolve("./x")).then(r => r.bytes()).then(_immutableUint8Array)); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } |
5 changes: 5 additions & 0 deletions
5
packages/babel-plugin-proposal-bytes-modules/test/fixtures/browser-and-node-esm/options.json
This file contains hidden or 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,5 @@ | ||
| { | ||
| "sourceType": "module", | ||
| "targets": { "firefox": "110", "node": "20.6" }, | ||
| "plugins": ["proposal-bytes-modules"] | ||
| } |
2 changes: 2 additions & 0 deletions
2
...lugin-proposal-bytes-modules/test/fixtures/browser-and-node-esm/with-json-import/input.js
This file contains hidden or 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 @@ | ||
| import bytes from "./x" with { type: "bytes" }; | ||
| import json from "./x" with { type: "json" }; |
5 changes: 5 additions & 0 deletions
5
...n-proposal-bytes-modules/test/fixtures/browser-and-node-esm/with-json-import/options.json
This file contains hidden or 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,5 @@ | ||
| { | ||
| "sourceType": "module", | ||
| "targets": { "firefox": "110", "node": "20.6" }, | ||
| "plugins": ["proposal-bytes-modules", "transform-json-modules"] | ||
| } |
3 changes: 3 additions & 0 deletions
3
...gin-proposal-bytes-modules/test/fixtures/browser-and-node-esm/with-json-import/output.mjs
This file contains hidden or 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 @@ | ||
| const json = await (typeof process === "object" && process.versions?.node ? import("fs").then(fs => fs.promises.readFile(new URL(import.meta.resolve("./x")))).then(JSON.parse) : fetch(import.meta.resolve("./x")).then(r => r.json())); | ||
| const bytes = await (typeof process === "object" && process.versions?.node ? import("fs").then(fs => fs.promises.readFile(new URL(import.meta.resolve("./x")))).then(_immutableUint8Array) : fetch(import.meta.resolve("./x")).then(r => r.bytes()).then(_immutableUint8Array)); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } |
3 changes: 3 additions & 0 deletions
3
...gin-proposal-bytes-modules/test/fixtures/browser-cjs/import-declaration-multiple/input.js
This file contains hidden or 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 j from "./x" with { type: "bytes" }; | ||
| someBody; | ||
| import j2 from "./x2" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
...proposal-bytes-modules/test/fixtures/browser-cjs/import-declaration-multiple/options.json
This file contains hidden or 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 @@ | ||
| { | ||
| "throws": "Cannot compile to CommonJS, since it would require top-level await." | ||
| } |
1 change: 1 addition & 0 deletions
1
...in-proposal-bytes-modules/test/fixtures/browser-cjs/import-declaration-namespace/input.js
This file contains hidden or 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 @@ | ||
| import * as ns from "./x" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
...roposal-bytes-modules/test/fixtures/browser-cjs/import-declaration-namespace/options.json
This file contains hidden or 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 @@ | ||
| { | ||
| "throws": "Cannot compile to CommonJS, since it would require top-level await." | ||
| } |
1 change: 1 addition & 0 deletions
1
...babel-plugin-proposal-bytes-modules/test/fixtures/browser-cjs/import-declaration/input.js
This file contains hidden or 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 @@ | ||
| import j from "./x" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
...l-plugin-proposal-bytes-modules/test/fixtures/browser-cjs/import-declaration/options.json
This file contains hidden or 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 @@ | ||
| { | ||
| "throws": "Cannot compile to CommonJS, since it would require top-level await." | ||
| } |
2 changes: 2 additions & 0 deletions
2
.../babel-plugin-proposal-bytes-modules/test/fixtures/browser-cjs/import-expression/input.js
This file contains hidden or 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 @@ | ||
| // TODO: Not supported yet | ||
| let promise = import("./x", { with: { type: "bytes" } }); |
8 changes: 8 additions & 0 deletions
8
...babel-plugin-proposal-bytes-modules/test/fixtures/browser-cjs/import-expression/output.js
This file contains hidden or 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,8 @@ | ||
| "use strict"; | ||
|
|
||
| // TODO: Not supported yet | ||
| let promise = import("./x", { | ||
| with: { | ||
| type: "bytes" | ||
| } | ||
| }); |
1 change: 1 addition & 0 deletions
1
...in-proposal-bytes-modules/test/fixtures/browser-cjs/import-meta-resolve-fallback/input.js
This file contains hidden or 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 @@ | ||
| import j from "./x" with { type: "bytes" }; |
4 changes: 4 additions & 0 deletions
4
...roposal-bytes-modules/test/fixtures/browser-cjs/import-meta-resolve-fallback/options.json
This file contains hidden or 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 @@ | ||
| { | ||
| "targets": { "firefox": "90" }, | ||
| "throws": "Cannot compile to CommonJS, since it would require top-level await." | ||
| } |
5 changes: 5 additions & 0 deletions
5
packages/babel-plugin-proposal-bytes-modules/test/fixtures/browser-cjs/options.json
This file contains hidden or 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,5 @@ | ||
| { | ||
| "sourceType": "module", | ||
| "targets": { "firefox": "110" }, | ||
| "plugins": ["proposal-bytes-modules", "transform-modules-commonjs"] | ||
| } |
3 changes: 3 additions & 0 deletions
3
...-plugin-proposal-bytes-modules/test/fixtures/browser/import-declaration-multiple/input.js
This file contains hidden or 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 j from "./x" with { type: "bytes" }; | ||
| someBody; | ||
| import j2 from "./x2" with { type: "bytes" }; |
3 changes: 3 additions & 0 deletions
3
...lugin-proposal-bytes-modules/test/fixtures/browser/import-declaration-multiple/output.mjs
This file contains hidden or 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 @@ | ||
| const [j, j2] = await Promise.all([fetch(import.meta.resolve("./x")).then(r => r.bytes()).then(_immutableUint8Array), fetch(import.meta.resolve("./x2")).then(r => r.bytes()).then(_immutableUint8Array)]); | ||
| function _immutableUint8Array(r) { var t = r.buffer; return new Uint8Array(t.transferToImmutable ? t.transferToImmutable() : t); } | ||
| someBody; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also do not support this for JSON yet.