generated from dellevin/template
1
This commit is contained in:
21
node_modules/acorn-import-phases/LICENSE
generated
vendored
Normal file
21
node_modules/acorn-import-phases/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Nicolò Ribaudo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
30
node_modules/acorn-import-phases/README.md
generated
vendored
Normal file
30
node_modules/acorn-import-phases/README.md
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# Support for `import defer` and `import souce` in acorn
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install acorn-import-phases
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
This module provides a plugin that can be used to extend the Acorn Parser class:
|
||||
|
||||
```js
|
||||
const {Parser} = require('acorn');
|
||||
const importPhases = require('acorn-import-phases');
|
||||
Parser.extend(importPhases()).parse('...');
|
||||
```
|
||||
|
||||
By default, the plugin supports both `import defer` and `import source` syntax. You can disable one of them by passing an options object:
|
||||
|
||||
```js
|
||||
const {Parser} = require('acorn');
|
||||
const importPhases = require('acorn-import-phases');
|
||||
Parser.extend(importPhases({ defer: false })).parse('...');
|
||||
Parser.extend(importPhases({ source: false })).parse('...');
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This plugin is released under an MIT License.
|
||||
46
node_modules/acorn-import-phases/package.json
generated
vendored
Normal file
46
node_modules/acorn-import-phases/package.json
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "acorn-import-phases",
|
||||
"version": "1.0.4",
|
||||
"description": "Support for `import <defer|source>` phase syntax in Acorn",
|
||||
"type": "module",
|
||||
"main": "./src/index.cjs",
|
||||
"types": "./src/index.d.cts",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": {
|
||||
"types": "./src/index.d.cts",
|
||||
"default": "./src/index.cjs"
|
||||
},
|
||||
"types": "./src/index.d.mts",
|
||||
"default": "./src/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --test ./test/index.js"
|
||||
},
|
||||
"keywords": [
|
||||
"acorn",
|
||||
"import",
|
||||
"defer",
|
||||
"source",
|
||||
"phase",
|
||||
"wasm",
|
||||
"proposal"
|
||||
],
|
||||
"author": "Nicolò Ribaudo",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nicolo-ribaudo/acorn-import-phases.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"acorn": "^8.14.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"acorn": "^8.14.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
}
|
||||
}
|
||||
5
node_modules/acorn-import-phases/src/index.cjs
generated
vendored
Normal file
5
node_modules/acorn-import-phases/src/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
const { plugin } = require("./plugin.cjs");
|
||||
|
||||
module.exports = function (options = {}) {
|
||||
return (Parser) => plugin(options, Parser, (Parser.acorn || require("acorn")).tokTypes);
|
||||
};
|
||||
9
node_modules/acorn-import-phases/src/index.d.cts
generated
vendored
Normal file
9
node_modules/acorn-import-phases/src/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Parser } from "acorn";
|
||||
|
||||
interface Options {
|
||||
source?: boolean;
|
||||
defer?: boolean;
|
||||
}
|
||||
|
||||
declare function acornImportPhases(options?: Options): (BaseParser: typeof Parser) => typeof Parser;
|
||||
export = acornImportPhases;
|
||||
8
node_modules/acorn-import-phases/src/index.d.mts
generated
vendored
Normal file
8
node_modules/acorn-import-phases/src/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Parser } from "acorn";
|
||||
|
||||
interface Options {
|
||||
source?: boolean;
|
||||
defer?: boolean;
|
||||
}
|
||||
|
||||
export default function acornImportPhases(options?: Options): (BaseParser: typeof Parser) => typeof Parser;
|
||||
6
node_modules/acorn-import-phases/src/index.js
generated
vendored
Normal file
6
node_modules/acorn-import-phases/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { tokTypes } from "acorn";
|
||||
import { plugin } from "./plugin.cjs";
|
||||
|
||||
export default function (options = {}) {
|
||||
return Parser => plugin(options, Parser, Parser.acorn ? Parser.acorn.tokTypes : tokTypes);
|
||||
}
|
||||
125
node_modules/acorn-import-phases/src/plugin.cjs
generated
vendored
Normal file
125
node_modules/acorn-import-phases/src/plugin.cjs
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* @param {{ defer?: boolean, source?: boolean }} options
|
||||
* @param {typeof import("acorn").Parser} Parser
|
||||
* @param {typeof import("acorn").tokTypes} acorn
|
||||
*/
|
||||
exports.plugin = function acornImportPhase(options, Parser, tt) {
|
||||
return class extends Parser {
|
||||
parseImport(node) {
|
||||
this._phase = null;
|
||||
const result = super.parseImport(node);
|
||||
if (this._phase) {
|
||||
node.phase = this._phase;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
parseImportSpecifiers() {
|
||||
let phase =
|
||||
options.defer !== false && this.isContextual("defer")
|
||||
? "defer"
|
||||
: options.source !== false && this.isContextual("source")
|
||||
? "source"
|
||||
: null;
|
||||
if (!phase) return super.parseImportSpecifiers();
|
||||
|
||||
const phaseId = this.parseIdent();
|
||||
if (this.isContextual("from") || this.type === tt.comma) {
|
||||
const defaultSpecifier = this.startNodeAt(phaseId.start, phaseId.loc && phaseId.loc.start);
|
||||
defaultSpecifier.local = phaseId;
|
||||
this.checkLValSimple(phaseId, /* BIND_LEXICAL */ 2);
|
||||
|
||||
const nodes = [this.finishNode(defaultSpecifier, "ImportDefaultSpecifier")];
|
||||
if (this.eat(tt.comma)) {
|
||||
if (this.type !== tt.star && this.type !== tt.braceL) {
|
||||
this.unexpected();
|
||||
}
|
||||
nodes.push(...super.parseImportSpecifiers());
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
this._phase = phase;
|
||||
|
||||
if (phase === "defer") {
|
||||
if (this.type !== tt.star) {
|
||||
this.raiseRecoverable(
|
||||
phaseId.start,
|
||||
"'import defer' can only be used with namespace imports ('import defer * as identifierName from ...')."
|
||||
);
|
||||
}
|
||||
} else if (phase === "source") {
|
||||
if (this.type !== tt.name) {
|
||||
this.raiseRecoverable(
|
||||
phaseId.start,
|
||||
"'import source' can only be used with direct identifier specifier imports."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const specifiers = super.parseImportSpecifiers();
|
||||
|
||||
if (phase === "source" && specifiers.some(s => s.type !== "ImportDefaultSpecifier")) {
|
||||
this.raiseRecoverable(
|
||||
phaseId.start,
|
||||
`'import source' can only be used with direct identifier specifier imports ('import source identifierName from ...').`
|
||||
);
|
||||
}
|
||||
|
||||
return specifiers;
|
||||
}
|
||||
|
||||
parseExprImport(forNew) {
|
||||
const node = super.parseExprImport(forNew);
|
||||
|
||||
if (node.type === "MetaProperty" && (node.property.name === "defer" || node.property.name === "source")) {
|
||||
if (this.type === tt.parenL) {
|
||||
const dynImport = this.parseDynamicImport(this.startNodeAt(node.start, node.loc && node.loc.start));
|
||||
dynImport.phase = node.property.name;
|
||||
return dynImport;
|
||||
} else {
|
||||
this.raiseRecoverable(
|
||||
node.start,
|
||||
`'import.${node.property.name}' can only be used in a dynamic import.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
parseImportMeta(node) {
|
||||
this.next();
|
||||
|
||||
var containsEsc = this.containsEsc;
|
||||
node.property = this.parseIdent(true);
|
||||
|
||||
const { name } = node.property;
|
||||
|
||||
if (name !== "meta" && name !== "defer" && name !== "source") {
|
||||
this.raiseRecoverable(
|
||||
node.property.start,
|
||||
"The only valid meta property for import is 'import.meta'"
|
||||
);
|
||||
}
|
||||
if (containsEsc) {
|
||||
this.raiseRecoverable(
|
||||
node.start,
|
||||
`'import.${name}' must not contain escaped characters`
|
||||
);
|
||||
}
|
||||
if (
|
||||
name === "meta" &&
|
||||
this.options.sourceType !== "module" &&
|
||||
!this.options.allowImportExportEverywhere
|
||||
) {
|
||||
this.raiseRecoverable(
|
||||
node.start,
|
||||
"Cannot use 'import.meta' outside a module"
|
||||
);
|
||||
}
|
||||
|
||||
return this.finishNode(node, "MetaProperty");
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user