Skip to content

Commit

Permalink
[v3.0] Basic support for import assertions (#4646)
Browse files Browse the repository at this point in the history
* Add acorn support for import assertions and extend AST

* Ignore pre-existing assertions on input files

* Naive support for JSON assertions in output

* Inject arbitrary import assertions

* Allows to disable import assertions altogether via `false`

* Support shorthand syntax for type assertions

* Keep assertions on fully dynamic imports

* Add documentation

* Add assertions to types

* Keep original assertions

* Make option a boolean

* Some extractions

* Allow plugins to add and change assertions

* Allow to pass assertions in this.resolve

* Warn for inconsistent import assertions

* Add new documentation

* Improve coverage
  • Loading branch information
lukastaegert committed Oct 11, 2022
1 parent 7c6bf53 commit 33d8c40
Show file tree
Hide file tree
Showing 87 changed files with 1,172 additions and 191 deletions.
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ Repository: https://github.com/acornjs/acorn.git
---------------------------------------

## acorn-import-assertions
License: MIT
By: Sven Sauleau
Repository: https://github.com/xtuc/acorn-import-assertions

---------------------------------------

## acorn-walk
License: MIT
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
Expand Down
7 changes: 7 additions & 0 deletions browser/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ Repository: https://github.com/acornjs/acorn.git
---------------------------------------

## acorn-import-assertions
License: MIT
By: Sven Sauleau
Repository: https://github.com/xtuc/acorn-import-assertions

---------------------------------------

## acorn-walk
License: MIT
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
Expand Down
22 changes: 7 additions & 15 deletions browser/src/resolveId.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type {
CustomPluginOptions,
Plugin,
ResolvedId,
ResolveIdResult
} from '../../src/rollup/types';
import { ModuleLoaderResolveId } from '../../src/ModuleLoader';
import type { CustomPluginOptions, Plugin, ResolveIdResult } from '../../src/rollup/types';
import type { PluginDriver } from '../../src/utils/PluginDriver';
import { resolveIdViaPlugins } from '../../src/utils/resolveIdViaPlugins';
import { throwNoFileSystem } from './error';
Expand All @@ -13,16 +9,11 @@ export async function resolveId(
importer: string | undefined,
_preserveSymlinks: boolean,
pluginDriver: PluginDriver,
moduleLoaderResolveId: (
source: string,
importer: string | undefined,
customOptions: CustomPluginOptions | undefined,
isEntry: boolean | undefined,
skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null
) => Promise<ResolvedId | null>,
moduleLoaderResolveId: ModuleLoaderResolveId,
skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null,
customOptions: CustomPluginOptions | undefined,
isEntry: boolean
isEntry: boolean,
assertions: Record<string, string>
): Promise<ResolveIdResult> {
const pluginResult = await resolveIdViaPlugins(
source,
Expand All @@ -31,7 +22,8 @@ export async function resolveId(
moduleLoaderResolveId,
skip,
customOptions,
isEntry
isEntry,
assertions
);
if (pluginResult == null) {
throwNoFileSystem('path.resolve');
Expand Down
5 changes: 3 additions & 2 deletions cli/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Basic options:
--exports <mode> Specify export mode (auto, default, named, none)
--extend Extend global variable defined by --name
--no-externalLiveBindings Do not generate code to support live bindings
--no-externalImportAssertions Omit import assertions in "es" output
--failAfterWarnings Exit with an error if the build produced warnings
--footer <text> Code to insert at end of bundle (outside wrapper)
--no-freeze Do not freeze namespace objects
Expand Down Expand Up @@ -68,8 +69,8 @@ Basic options:
--no-systemNullSetters Do not replace empty SystemJS setters with `null`
--no-treeshake Disable tree-shaking optimisations
--no-treeshake.annotations Ignore pure call annotations
--no-treeshake.moduleSideEffects Assume modules have no side-effects
--no-treeshake.propertyReadSideEffects Ignore property access side-effects
--no-treeshake.moduleSideEffects Assume modules have no side effects
--no-treeshake.propertyReadSideEffects Ignore property access side effects
--no-treeshake.tryCatchDeoptimization Do not turn off try-catch-tree-shaking
--no-treeshake.unknownGlobalSideEffects Assume unknown globals do not throw
--waitForBundleInput Wait for bundle input files
Expand Down
5 changes: 3 additions & 2 deletions docs/01-command-line-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ Many options have command line equivalents. In those cases, any arguments passed
--no-esModule Do not add __esModule property
--exports <mode> Specify export mode (auto, default, named, none)
--extend Extend global variable defined by --name
--no-externalImportAssertions Omit import assertions in "es" output
--no-externalLiveBindings Do not generate code to support live bindings
--failAfterWarnings Exit with an error if the build produced warnings
--footer <text> Code to insert at end of bundle (outside wrapper)
Expand Down Expand Up @@ -399,8 +400,8 @@ Many options have command line equivalents. In those cases, any arguments passed
--no-systemNullSetters Do not replace empty SystemJS setters with `null`
--no-treeshake Disable tree-shaking optimisations
--no-treeshake.annotations Ignore pure call annotations
--no-treeshake.moduleSideEffects Assume modules have no side-effects
--no-treeshake.propertyReadSideEffects Ignore property access side-effects
--no-treeshake.moduleSideEffects Assume modules have no side effects
--no-treeshake.propertyReadSideEffects Ignore property access side effects
--no-treeshake.tryCatchDeoptimization Do not turn off try-catch-tree-shaking
--no-treeshake.unknownGlobalSideEffects Assume unknown globals do not throw
--waitForBundleInput Wait for bundle input files
Expand Down
Loading

0 comments on commit 33d8c40

Please sign in to comment.