@taktikorg/quia-veniam v3.9.98
@taktikorg/quia-veniam
Import attributes for acorn.
Parses to the stage3 Import Attributes ESTree extension.
Supports both the with
and deprecated assert
keywords. Both are parsed to the same tree structure. A property attributesKeyword
is added to expose which keyword was present in the source.
Usage
npm install @taktikorg/quia-veniam
import * as acorn from 'acorn'
import importAttributes from '@taktikorg/quia-veniam'
const Parser = acorn.Parser.extend(
importAttributes({ with: true, assert: true })
)
const source = `
import config from 'config.json' with { type: 'json' }
`.trim()
const tree = Parser.parse(source, {
ecmaVersion: 'latest',
sourceType: 'module'
})
{
type: 'Program',
body: [{
type: 'ImportDeclaration',
specifiers: [..],
source: ..,
attributesKeyword: 'with',
attributes: [{
type: 'ImportAttribute',
key: { type: 'Identifier', name: 'type' },
value: { type: 'Literal', value: 'json' }
}]
}]
}
API
importAttributes(options)
The default export is a factory function which produces a plugin. Pass an options object to configure which keywords to recognize.
Options
Name | Type | Description | Default |
---|---|---|---|
with | boolean | Recognize with as an import attributes keyword. | true |
assert | boolean | Recognize assert as an import attributes keyword. | false |
ESTree
Extensions to the Import Attributes ESTree structure. attributesKeyword
is null
when no attributes are present.
ImportDeclaration
extend interface ImportDeclaration {
attributesKeyword: "with" | "assert" | null;
}
ExportNamedDeclaration
extend interface ExportNamedDeclaration {
attributesKeyword: "with" | "assert" | null;
}
ExportAllDeclaration
extend interface ExportAllDeclaration {
attributesKeyword: "with" | "assert" | null;
}
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago