Fix code quality violations and enhance ROUTE-EXISTS-01 rule
Implement JQHTML function cache ID system and fix bundle compilation Implement underscore prefix for system tables Fix JS syntax linter to support decorators and grant exception to Task system SPA: Update planning docs and wishlists with remaining features SPA: Document Navigation API abandonment and future enhancements Implement SPA browser integration with History API (Phase 1) Convert contacts view page to SPA action Convert clients pages to SPA actions and document conversion procedure SPA: Merge GET parameters and update documentation Implement SPA route URL generation in JavaScript and PHP Implement SPA bootstrap controller architecture Add SPA routing manual page (rsx:man spa) Add SPA routing documentation to CLAUDE.md Phase 4 Complete: Client-side SPA routing implementation Update get_routes() consumers for unified route structure Complete SPA Phase 3: PHP-side route type detection and is_spa flag Restore unified routes structure and Manifest_Query class Refactor route indexing and add SPA infrastructure Phase 3 Complete: SPA route registration in manifest Implement SPA Phase 2: Extract router code and test decorators Rename Jqhtml_Component to Component and complete SPA foundation setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
0
node_modules/webpack/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/BasicEvaluatedExpression.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/BasicEvaluatedExpression.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/ChunkFormatHelpers.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/ChunkFormatHelpers.js
generated
vendored
Executable file → Normal file
21
node_modules/webpack/lib/javascript/ChunkHelpers.js
generated
vendored
Executable file → Normal file
21
node_modules/webpack/lib/javascript/ChunkHelpers.js
generated
vendored
Executable file → Normal file
@@ -16,17 +16,28 @@ const Entrypoint = require("../Entrypoint");
|
||||
* @returns {Set<Chunk>} chunks
|
||||
*/
|
||||
const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
|
||||
/** @type {Set<Entrypoint>} */
|
||||
const queue = new Set([entrypoint]);
|
||||
/** @type {Set<Entrypoint>} */
|
||||
const groups = new Set([]);
|
||||
for (const group of queue) {
|
||||
if (group !== entrypoint) {
|
||||
groups.add(group);
|
||||
}
|
||||
for (const parent of group.parentsIterable) {
|
||||
if (parent instanceof Entrypoint) queue.add(parent);
|
||||
}
|
||||
}
|
||||
groups.add(entrypoint);
|
||||
|
||||
/** @type {Set<Chunk>} */
|
||||
const chunks = new Set();
|
||||
for (const entrypoint of queue) {
|
||||
for (const chunk of entrypoint.chunks) {
|
||||
for (const group of groups) {
|
||||
for (const chunk of group.chunks) {
|
||||
if (chunk === excludedChunk1) continue;
|
||||
if (chunk === excludedChunk2) continue;
|
||||
chunks.add(chunk);
|
||||
}
|
||||
for (const parent of entrypoint.parentsIterable) {
|
||||
if (parent instanceof Entrypoint) queue.add(parent);
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
};
|
||||
|
||||
0
node_modules/webpack/lib/javascript/CommonJsChunkFormatPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/CommonJsChunkFormatPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/EnableChunkLoadingPlugin.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/EnableChunkLoadingPlugin.js
generated
vendored
Executable file → Normal file
202
node_modules/webpack/lib/javascript/JavascriptGenerator.js
generated
vendored
Executable file → Normal file
202
node_modules/webpack/lib/javascript/JavascriptGenerator.js
generated
vendored
Executable file → Normal file
@@ -101,107 +101,6 @@ class JavascriptGenerator extends Generator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NormalModule} module module for which the code should be generated
|
||||
* @param {GenerateContext} generateContext context for generate
|
||||
* @returns {Source | null} generated code
|
||||
*/
|
||||
generate(module, generateContext) {
|
||||
const originalSource = module.originalSource();
|
||||
if (!originalSource) {
|
||||
return DEFAULT_SOURCE.source();
|
||||
}
|
||||
|
||||
const source = new ReplaceSource(originalSource);
|
||||
/** @type {InitFragment<GenerateContext>[]} */
|
||||
const initFragments = [];
|
||||
|
||||
this.sourceModule(module, initFragments, source, generateContext);
|
||||
|
||||
return InitFragment.addToSource(source, initFragments, generateContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Error} error the error
|
||||
* @param {NormalModule} module module for which the code should be generated
|
||||
* @param {GenerateContext} generateContext context for generate
|
||||
* @returns {Source | null} generated code
|
||||
*/
|
||||
generateError(error, module, generateContext) {
|
||||
return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module to generate
|
||||
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
||||
* @param {ReplaceSource} source the current replace source which can be modified
|
||||
* @param {GenerateContext} generateContext the generateContext
|
||||
* @returns {void}
|
||||
*/
|
||||
sourceModule(module, initFragments, source, generateContext) {
|
||||
for (const dependency of module.dependencies) {
|
||||
this.sourceDependency(
|
||||
module,
|
||||
dependency,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
|
||||
if (module.presentationalDependencies !== undefined) {
|
||||
for (const dependency of module.presentationalDependencies) {
|
||||
this.sourceDependency(
|
||||
module,
|
||||
dependency,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const childBlock of module.blocks) {
|
||||
this.sourceBlock(
|
||||
module,
|
||||
childBlock,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module to generate
|
||||
* @param {DependenciesBlock} block the dependencies block which will be processed
|
||||
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
||||
* @param {ReplaceSource} source the current replace source which can be modified
|
||||
* @param {GenerateContext} generateContext the generateContext
|
||||
* @returns {void}
|
||||
*/
|
||||
sourceBlock(module, block, initFragments, source, generateContext) {
|
||||
for (const dependency of block.dependencies) {
|
||||
this.sourceDependency(
|
||||
module,
|
||||
dependency,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
|
||||
for (const childBlock of block.blocks) {
|
||||
this.sourceBlock(
|
||||
module,
|
||||
childBlock,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the current module
|
||||
* @param {Dependency} dependency the dependency to generate
|
||||
@@ -271,6 +170,107 @@ class JavascriptGenerator extends Generator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module to generate
|
||||
* @param {DependenciesBlock} block the dependencies block which will be processed
|
||||
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
||||
* @param {ReplaceSource} source the current replace source which can be modified
|
||||
* @param {GenerateContext} generateContext the generateContext
|
||||
* @returns {void}
|
||||
*/
|
||||
sourceBlock(module, block, initFragments, source, generateContext) {
|
||||
for (const dependency of block.dependencies) {
|
||||
this.sourceDependency(
|
||||
module,
|
||||
dependency,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
|
||||
for (const childBlock of block.blocks) {
|
||||
this.sourceBlock(
|
||||
module,
|
||||
childBlock,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module to generate
|
||||
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
||||
* @param {ReplaceSource} source the current replace source which can be modified
|
||||
* @param {GenerateContext} generateContext the generateContext
|
||||
* @returns {void}
|
||||
*/
|
||||
sourceModule(module, initFragments, source, generateContext) {
|
||||
for (const dependency of module.dependencies) {
|
||||
this.sourceDependency(
|
||||
module,
|
||||
dependency,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
|
||||
if (module.presentationalDependencies !== undefined) {
|
||||
for (const dependency of module.presentationalDependencies) {
|
||||
this.sourceDependency(
|
||||
module,
|
||||
dependency,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const childBlock of module.blocks) {
|
||||
this.sourceBlock(
|
||||
module,
|
||||
childBlock,
|
||||
initFragments,
|
||||
source,
|
||||
generateContext
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NormalModule} module module for which the code should be generated
|
||||
* @param {GenerateContext} generateContext context for generate
|
||||
* @returns {Source | null} generated code
|
||||
*/
|
||||
generate(module, generateContext) {
|
||||
const originalSource = module.originalSource();
|
||||
if (!originalSource) {
|
||||
return DEFAULT_SOURCE.source();
|
||||
}
|
||||
|
||||
const source = new ReplaceSource(originalSource);
|
||||
/** @type {InitFragment<GenerateContext>[]} */
|
||||
const initFragments = [];
|
||||
|
||||
this.sourceModule(module, initFragments, source, generateContext);
|
||||
|
||||
return InitFragment.addToSource(source, initFragments, generateContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Error} error the error
|
||||
* @param {NormalModule} module module for which the code should be generated
|
||||
* @param {GenerateContext} generateContext context for generate
|
||||
* @returns {Source | null} generated code
|
||||
*/
|
||||
generateError(error, module, generateContext) {
|
||||
return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JavascriptGenerator;
|
||||
|
||||
36
node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js
generated
vendored
Executable file → Normal file
36
node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js
generated
vendored
Executable file → Normal file
@@ -298,16 +298,20 @@ class JavascriptModulesPlugin {
|
||||
]) {
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for(type)
|
||||
.tap(PLUGIN_NAME, (_options) => {
|
||||
.tap(PLUGIN_NAME, (options) => {
|
||||
switch (type) {
|
||||
case JAVASCRIPT_MODULE_TYPE_AUTO: {
|
||||
return new JavascriptParser("auto");
|
||||
return new JavascriptParser("auto", { parse: options.parse });
|
||||
}
|
||||
case JAVASCRIPT_MODULE_TYPE_DYNAMIC: {
|
||||
return new JavascriptParser("script");
|
||||
return new JavascriptParser("script", {
|
||||
parse: options.parse
|
||||
});
|
||||
}
|
||||
case JAVASCRIPT_MODULE_TYPE_ESM: {
|
||||
return new JavascriptParser("module");
|
||||
return new JavascriptParser("module", {
|
||||
parse: options.parse
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -950,7 +954,8 @@ class JavascriptModulesPlugin {
|
||||
let inlinedInIIFE = false;
|
||||
|
||||
if (avoidEntryIife) {
|
||||
renamedInlinedModule = this.getRenamedInlineModule(
|
||||
renamedInlinedModule = this._getRenamedInlineModule(
|
||||
compilation,
|
||||
allModules,
|
||||
renderContext,
|
||||
inlinedModules,
|
||||
@@ -1584,10 +1589,7 @@ class JavascriptModulesPlugin {
|
||||
"// Execute the module function",
|
||||
moduleExecution,
|
||||
...(needModuleDefer
|
||||
? [
|
||||
"// delete __webpack_module_deferred_exports__[module];",
|
||||
"// skipped because strictModuleErrorHandling is not enabled."
|
||||
]
|
||||
? ["delete __webpack_module_deferred_exports__[moduleId];"]
|
||||
: [])
|
||||
]),
|
||||
needModuleLoaded
|
||||
@@ -1608,6 +1610,7 @@ class JavascriptModulesPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compilation} compilation compilation
|
||||
* @param {Module[]} allModules allModules
|
||||
* @param {MainRenderContext} renderContext renderContext
|
||||
* @param {Set<Module>} inlinedModules inlinedModules
|
||||
@@ -1617,7 +1620,8 @@ class JavascriptModulesPlugin {
|
||||
* @param {boolean} hasChunkModules hasChunkModules
|
||||
* @returns {Map<Module, Source> | false} renamed inlined modules
|
||||
*/
|
||||
getRenamedInlineModule(
|
||||
_getRenamedInlineModule(
|
||||
compilation,
|
||||
allModules,
|
||||
renderContext,
|
||||
inlinedModules,
|
||||
@@ -1664,9 +1668,15 @@ class JavascriptModulesPlugin {
|
||||
|
||||
if (!moduleSource) continue;
|
||||
const code = /** @type {string} */ (moduleSource.source());
|
||||
const ast = JavascriptParser._parse(code, {
|
||||
sourceType: "auto"
|
||||
});
|
||||
|
||||
const { ast } = JavascriptParser._parse(
|
||||
code,
|
||||
{
|
||||
sourceType: "auto",
|
||||
ranges: true
|
||||
},
|
||||
JavascriptParser._getModuleParseFunction(compilation, m)
|
||||
);
|
||||
|
||||
const scopeManager = eslintScope.analyze(ast, {
|
||||
ecmaVersion: 6,
|
||||
|
||||
182
node_modules/webpack/lib/javascript/JavascriptParser.js
generated
vendored
Executable file → Normal file
182
node_modules/webpack/lib/javascript/JavascriptParser.js
generated
vendored
Executable file → Normal file
@@ -8,6 +8,7 @@
|
||||
const vm = require("vm");
|
||||
const { Parser: AcornParser, tokTypes } = require("acorn");
|
||||
const { HookMap, SyncBailHook } = require("tapable");
|
||||
const NormalModule = require("../NormalModule");
|
||||
const Parser = require("../Parser");
|
||||
const StackedMap = require("../util/StackedMap");
|
||||
const binarySearchBounds = require("../util/binarySearchBounds");
|
||||
@@ -19,6 +20,7 @@ const memoize = require("../util/memoize");
|
||||
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
||||
|
||||
/** @typedef {import("acorn").Options} AcornOptions */
|
||||
/** @typedef {import("acorn").ecmaVersion} EcmaVersion */
|
||||
/** @typedef {import("estree").AssignmentExpression} AssignmentExpression */
|
||||
/** @typedef {import("estree").BinaryExpression} BinaryExpression */
|
||||
/** @typedef {import("estree").BlockStatement} BlockStatement */
|
||||
@@ -29,7 +31,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
||||
/** @typedef {import("estree").ForStatement} ForStatement */
|
||||
/** @typedef {import("estree").SwitchStatement} SwitchStatement */
|
||||
/** @typedef {import("estree").ClassExpression} ClassExpression */
|
||||
/** @typedef {import("estree").Comment} Comment */
|
||||
/** @typedef {import("estree").SourceLocation} SourceLocation */
|
||||
/** @typedef {import("estree").Comment & { start: number, end: number, loc: SourceLocation }} Comment */
|
||||
/** @typedef {import("estree").ConditionalExpression} ConditionalExpression */
|
||||
/** @typedef {import("estree").Declaration} Declaration */
|
||||
/** @typedef {import("estree").PrivateIdentifier} PrivateIdentifier */
|
||||
@@ -97,6 +100,9 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
||||
/** @typedef {import("../Parser").ParserState} ParserState */
|
||||
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
||||
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
|
||||
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} GetInfoResult */
|
||||
/** @typedef {Statement | ModuleDeclaration | Expression | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration} StatementPathItem */
|
||||
/** @typedef {(ident: string) => void} OnIdentString */
|
||||
@@ -297,7 +303,33 @@ class VariableInfo {
|
||||
|
||||
/** @typedef {string | ScopeInfo | VariableInfo} ExportedVariableInfo */
|
||||
/** @typedef {Literal | string | null | undefined} ImportSource */
|
||||
/** @typedef {Omit<AcornOptions, "sourceType" | "ecmaVersion"> & { sourceType: "module" | "script" | "auto", ecmaVersion?: AcornOptions["ecmaVersion"] }} ParseOptions */
|
||||
|
||||
/**
|
||||
* @typedef {Omit<ParseOptions, "sourceType"> & {sourceType: "module" | "script" | "auto"}} InternalParseOptions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} ParseOptions
|
||||
* @property {"module" | "script"} sourceType
|
||||
* @property {EcmaVersion=} ecmaVersion
|
||||
* @property {boolean=} locations
|
||||
* @property {boolean=} comments
|
||||
* @property {boolean=} ranges
|
||||
* @property {boolean=} semicolons
|
||||
* @property {boolean=} allowHashBang
|
||||
* @property {boolean=} allowReturnOutsideFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} ParseResult
|
||||
* @property {Program} ast
|
||||
* @property {Comment[]} comments
|
||||
* @property {Set<number>} semicolons
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {(code: string, options: ParseOptions) => ParseResult} ParseFunction
|
||||
*/
|
||||
|
||||
/** @typedef {symbol} Tag */
|
||||
|
||||
@@ -343,6 +375,7 @@ const SCOPE_INFO_TERMINATED_THROW = 2;
|
||||
* @typedef {object} DestructuringAssignmentProperty
|
||||
* @property {string} id
|
||||
* @property {Range} range
|
||||
* @property {SourceLocation} loc
|
||||
* @property {Set<DestructuringAssignmentProperty> | undefined=} pattern
|
||||
* @property {boolean | string} shorthand
|
||||
*/
|
||||
@@ -412,15 +445,15 @@ const getRootName = (expression) => {
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {AcornOptions} */
|
||||
/** @type {ParseOptions} */
|
||||
const defaultParserOptions = {
|
||||
ranges: true,
|
||||
locations: true,
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
ecmaVersion: "latest",
|
||||
ranges: false,
|
||||
locations: false,
|
||||
comments: false,
|
||||
// https://github.com/tc39/proposal-hashbang
|
||||
allowHashBang: true,
|
||||
onComment: undefined
|
||||
allowHashBang: true
|
||||
};
|
||||
|
||||
const EMPTY_COMMENT_OPTIONS = {
|
||||
@@ -432,9 +465,10 @@ const CLASS_NAME = "JavascriptParser";
|
||||
|
||||
class JavascriptParser extends Parser {
|
||||
/**
|
||||
* @param {"module" | "script" | "auto"} sourceType default source type
|
||||
* @param {"module" | "script" | "auto"=} sourceType default source type
|
||||
* @param {{ parse?: ParseFunction }=} options parser options
|
||||
*/
|
||||
constructor(sourceType = "auto") {
|
||||
constructor(sourceType = "auto", options = {}) {
|
||||
super();
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {HookMap<SyncBailHook<[UnaryExpression], BasicEvaluatedExpression | null | undefined>>} */
|
||||
@@ -628,6 +662,8 @@ class JavascriptParser extends Parser {
|
||||
unusedStatement: new SyncBailHook(["statement"])
|
||||
});
|
||||
this.sourceType = sourceType;
|
||||
this.options = options;
|
||||
|
||||
/** @type {ScopeInfo} */
|
||||
this.scope = /** @type {EXPECTED_ANY} */ (undefined);
|
||||
/** @type {ParserState} */
|
||||
@@ -3003,6 +3039,7 @@ class JavascriptParser extends Parser {
|
||||
props.add({
|
||||
id: key.name,
|
||||
range: /** @type {Range} */ (key.range),
|
||||
loc: /** @type {SourceLocation} */ (key.loc),
|
||||
pattern,
|
||||
shorthand: this.scope.inShorthand
|
||||
});
|
||||
@@ -3019,6 +3056,7 @@ class JavascriptParser extends Parser {
|
||||
props.add({
|
||||
id: str,
|
||||
range: /** @type {Range} */ (key.range),
|
||||
loc: /** @type {SourceLocation} */ (key.loc),
|
||||
pattern,
|
||||
shorthand: this.scope.inShorthand
|
||||
});
|
||||
@@ -3054,6 +3092,7 @@ class JavascriptParser extends Parser {
|
||||
props.add({
|
||||
id: `${i}`,
|
||||
range: /** @type {Range} */ (element.range),
|
||||
loc: /** @type {SourceLocation} */ (element.loc),
|
||||
pattern,
|
||||
shorthand: false
|
||||
});
|
||||
@@ -4626,17 +4665,23 @@ class JavascriptParser extends Parser {
|
||||
* @returns {ParserState} the parser state
|
||||
*/
|
||||
parse(source, state) {
|
||||
let ast;
|
||||
/** @type {import("acorn").Comment[]} */
|
||||
let comments;
|
||||
const semicolons = new Set();
|
||||
if (source === null) {
|
||||
throw new Error("source must not be null");
|
||||
}
|
||||
|
||||
if (Buffer.isBuffer(source)) {
|
||||
source = source.toString("utf8");
|
||||
}
|
||||
|
||||
let ast;
|
||||
/** @type {Comment[]} */
|
||||
let comments;
|
||||
/** @type {Set<number>} */
|
||||
let semicolons;
|
||||
|
||||
if (typeof source === "object") {
|
||||
semicolons = new Set();
|
||||
|
||||
ast = /** @type {Program} */ (source);
|
||||
comments = source.comments;
|
||||
if (source.semicolons) {
|
||||
@@ -4647,12 +4692,17 @@ class JavascriptParser extends Parser {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
comments = [];
|
||||
ast = JavascriptParser._parse(source, {
|
||||
sourceType: this.sourceType,
|
||||
onComment: comments,
|
||||
onInsertedSemicolon: (pos) => semicolons.add(pos)
|
||||
});
|
||||
({ ast, comments, semicolons } = JavascriptParser._parse(
|
||||
source,
|
||||
{
|
||||
sourceType: this.sourceType,
|
||||
locations: true,
|
||||
ranges: true,
|
||||
comments: true,
|
||||
semicolons: true
|
||||
},
|
||||
this.options.parse
|
||||
));
|
||||
}
|
||||
|
||||
const oldScope = this.scope;
|
||||
@@ -4702,10 +4752,11 @@ class JavascriptParser extends Parser {
|
||||
* @returns {BasicEvaluatedExpression} evaluation result
|
||||
*/
|
||||
evaluate(source) {
|
||||
const ast = JavascriptParser._parse(`(${source})`, {
|
||||
sourceType: this.sourceType,
|
||||
locations: false
|
||||
});
|
||||
const { ast } = JavascriptParser._parse(
|
||||
`(${source})`,
|
||||
{ sourceType: this.sourceType },
|
||||
this.options.parse
|
||||
);
|
||||
if (ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement") {
|
||||
throw new Error("evaluate: Source is not a expression");
|
||||
}
|
||||
@@ -5256,26 +5307,83 @@ class JavascriptParser extends Parser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} code source code
|
||||
* @param {ParseOptions} options parsing options
|
||||
* @returns {Program} parsed ast
|
||||
* @param {Compilation} compilation compilation
|
||||
* @param {Module} module module
|
||||
* @returns {ParseFunction | undefined} parser
|
||||
*/
|
||||
static _parse(code, options) {
|
||||
static _getModuleParseFunction(compilation, module) {
|
||||
// Get from module if available
|
||||
if (
|
||||
module instanceof NormalModule &&
|
||||
module.parser instanceof JavascriptParser
|
||||
) {
|
||||
return module.parser.options.parse;
|
||||
}
|
||||
|
||||
// Fallback to the global javascript parse function
|
||||
if (typeof compilation.options.module.parser.javascript !== "undefined") {
|
||||
return compilation.options.module.parser.javascript.parse;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} code source code
|
||||
* @param {InternalParseOptions} options parsing options
|
||||
* @param {ParseFunction=} customParse custom function to parse
|
||||
* @returns {ParseResult} parse result
|
||||
*/
|
||||
static _parse(code, options, customParse) {
|
||||
const type = options ? options.sourceType : "module";
|
||||
/** @type {AcornOptions} */
|
||||
/** @type {ParseOptions} */
|
||||
const parserOptions = {
|
||||
...defaultParserOptions,
|
||||
allowReturnOutsideFunction: type === "script",
|
||||
...options,
|
||||
sourceType: type === "auto" ? "module" : type
|
||||
};
|
||||
/**
|
||||
* @param {string} code source code
|
||||
* @param {ParseOptions} options parsing options
|
||||
* @returns {ParseResult} parse result
|
||||
*/
|
||||
const internalParse = (code, options) => {
|
||||
if (typeof customParse === "function") {
|
||||
return customParse(code, options);
|
||||
}
|
||||
|
||||
/** @type {import("acorn").Program | undefined} */
|
||||
/** @type {Comment[]} */
|
||||
const comments = [];
|
||||
|
||||
if (options.comments) {
|
||||
/** @type {AcornOptions} */
|
||||
(options).onComment = comments;
|
||||
}
|
||||
|
||||
/** @type {Set<number>} */
|
||||
const semicolons = new Set();
|
||||
|
||||
if (options.semicolons) {
|
||||
/** @type {AcornOptions} */
|
||||
(options).onInsertedSemicolon = (pos) => semicolons.add(pos);
|
||||
}
|
||||
|
||||
const ast =
|
||||
/** @type {Program} */
|
||||
(parser.parse(code, /** @type {AcornOptions} */ (options)));
|
||||
|
||||
return { ast, comments, semicolons };
|
||||
};
|
||||
|
||||
/** @type {Program | undefined} */
|
||||
let ast;
|
||||
/** @type {Comment[] | undefined} */
|
||||
let comments;
|
||||
/** @type {Set<number> | undefined} */
|
||||
let semicolons;
|
||||
let error;
|
||||
let threw = false;
|
||||
try {
|
||||
ast = parser.parse(code, parserOptions);
|
||||
({ ast, comments, semicolons } = internalParse(code, parserOptions));
|
||||
} catch (err) {
|
||||
error = err;
|
||||
threw = true;
|
||||
@@ -5283,14 +5391,10 @@ class JavascriptParser extends Parser {
|
||||
|
||||
if (threw && type === "auto") {
|
||||
parserOptions.sourceType = "script";
|
||||
if (!("allowReturnOutsideFunction" in options)) {
|
||||
parserOptions.allowReturnOutsideFunction = true;
|
||||
}
|
||||
if (Array.isArray(parserOptions.onComment)) {
|
||||
parserOptions.onComment.length = 0;
|
||||
}
|
||||
parserOptions.allowReturnOutsideFunction = true;
|
||||
|
||||
try {
|
||||
ast = parser.parse(code, parserOptions);
|
||||
({ ast, comments, semicolons } = internalParse(code, parserOptions));
|
||||
threw = false;
|
||||
} catch (_err) {
|
||||
// we use the error from first parse try
|
||||
@@ -5302,7 +5406,7 @@ class JavascriptParser extends Parser {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return /** @type {Program} */ (ast);
|
||||
return /** @type {ParseResult} */ ({ ast, comments, semicolons });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
0
node_modules/webpack/lib/javascript/JavascriptParserHelpers.js
generated
vendored
Executable file → Normal file
0
node_modules/webpack/lib/javascript/JavascriptParserHelpers.js
generated
vendored
Executable file → Normal file
Reference in New Issue
Block a user