Add semantic token highlighting for 'that' variable and comment file references in VS Code extension Add Phone_Text_Input and Currency_Input components with formatting utilities Implement client widgets, form standardization, and soft delete functionality Add modal scroll lock and update documentation Implement comprehensive modal system with form integration and validation Fix modal component instantiation using jQuery plugin API Implement modal system with responsive sizing, queuing, and validation support Implement form submission with validation, error handling, and loading states Implement country/state selectors with dynamic data loading and Bootstrap styling Revert Rsx::Route() highlighting in Blade/PHP files Target specific PHP scopes for Rsx::Route() highlighting in Blade Expand injection selector for Rsx::Route() highlighting Add custom syntax highlighting for Rsx::Route() and Rsx.Route() calls Update jqhtml packages to v2.2.165 Add bundle path validation for common mistakes (development mode only) Create Ajax_Select_Input widget and Rsx_Reference_Data controller Create Country_Select_Input widget with default country support Initialize Tom Select on Select_Input widgets Add Tom Select bundle for enhanced select dropdowns Implement ISO 3166 geographic data system for country/region selection Implement widget-based form system with disabled state support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
277 lines
8.5 KiB
JavaScript
Executable File
277 lines
8.5 KiB
JavaScript
Executable File
/*
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
Author Tobias Koppers @sokra
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
const util = require("util");
|
|
const { RawSource, ReplaceSource } = require("webpack-sources");
|
|
const Generator = require("../Generator");
|
|
const InitFragment = require("../InitFragment");
|
|
const { JS_TYPES } = require("../ModuleSourceTypesConstants");
|
|
const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
|
|
|
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
/** @typedef {import("../Compilation").DependencyConstructor} DependencyConstructor */
|
|
/** @typedef {import("../DependenciesBlock")} DependenciesBlock */
|
|
/** @typedef {import("../Dependency")} Dependency */
|
|
/** @typedef {import("../DependencyTemplate")} DependencyTemplate */
|
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
/** @typedef {import("../Module")} Module */
|
|
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
|
|
const DEFAULT_SOURCE = {
|
|
source() {
|
|
return new RawSource("throw new Error('No source available');");
|
|
},
|
|
/**
|
|
* @returns {number} size of the DEFAULT_SOURCE.source()
|
|
*/
|
|
size() {
|
|
return 39;
|
|
}
|
|
};
|
|
|
|
// TODO: clean up this file
|
|
// replace with newer constructs
|
|
|
|
const deprecatedGetInitFragments = util.deprecate(
|
|
/**
|
|
* @param {DependencyTemplate} template template
|
|
* @param {Dependency} dependency dependency
|
|
* @param {DependencyTemplateContext} templateContext template context
|
|
* @returns {InitFragment<GenerateContext>[]} init fragments
|
|
*/
|
|
(template, dependency, templateContext) =>
|
|
/** @type {DependencyTemplate & { getInitFragments: (dependency: Dependency, dependencyTemplateContext: DependencyTemplateContext) => InitFragment<GenerateContext>[] }} */
|
|
(template).getInitFragments(dependency, templateContext),
|
|
"DependencyTemplate.getInitFragment is deprecated (use apply(dep, source, { initFragments }) instead)",
|
|
"DEP_WEBPACK_JAVASCRIPT_GENERATOR_GET_INIT_FRAGMENTS"
|
|
);
|
|
|
|
class JavascriptGenerator extends Generator {
|
|
/**
|
|
* @param {NormalModule} module fresh module
|
|
* @returns {SourceTypes} available types (do not mutate)
|
|
*/
|
|
getTypes(module) {
|
|
return JS_TYPES;
|
|
}
|
|
|
|
/**
|
|
* @param {NormalModule} module the module
|
|
* @param {string=} type source type
|
|
* @returns {number} estimate size of the module
|
|
*/
|
|
getSize(module, type) {
|
|
const originalSource = module.originalSource();
|
|
if (!originalSource) {
|
|
return DEFAULT_SOURCE.size();
|
|
}
|
|
return originalSource.size();
|
|
}
|
|
|
|
/**
|
|
* @param {NormalModule} module module for which the bailout reason should be determined
|
|
* @param {ConcatenationBailoutReasonContext} context context
|
|
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
*/
|
|
getConcatenationBailoutReason(module, context) {
|
|
// Only harmony modules are valid for optimization
|
|
if (
|
|
!module.buildMeta ||
|
|
module.buildMeta.exportsType !== "namespace" ||
|
|
module.presentationalDependencies === undefined ||
|
|
!module.presentationalDependencies.some(
|
|
(d) => d instanceof HarmonyCompatibilityDependency
|
|
)
|
|
) {
|
|
return "Module is not an ECMAScript module";
|
|
}
|
|
|
|
// Some expressions are not compatible with module concatenation
|
|
// because they may produce unexpected results. The plugin bails out
|
|
// if some were detected upfront.
|
|
if (module.buildInfo && module.buildInfo.moduleConcatenationBailout) {
|
|
return `Module uses ${module.buildInfo.moduleConcatenationBailout}`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
|
* @param {ReplaceSource} source the current replace source which can be modified
|
|
* @param {GenerateContext} generateContext the render context
|
|
* @returns {void}
|
|
*/
|
|
sourceDependency(module, dependency, initFragments, source, generateContext) {
|
|
const constructor =
|
|
/** @type {DependencyConstructor} */
|
|
(dependency.constructor);
|
|
const template = generateContext.dependencyTemplates.get(constructor);
|
|
if (!template) {
|
|
throw new Error(
|
|
`No template for dependency: ${dependency.constructor.name}`
|
|
);
|
|
}
|
|
|
|
/** @type {InitFragment<GenerateContext>[] | undefined} */
|
|
let chunkInitFragments;
|
|
|
|
/** @type {DependencyTemplateContext} */
|
|
const templateContext = {
|
|
runtimeTemplate: generateContext.runtimeTemplate,
|
|
dependencyTemplates: generateContext.dependencyTemplates,
|
|
moduleGraph: generateContext.moduleGraph,
|
|
chunkGraph: generateContext.chunkGraph,
|
|
module,
|
|
runtime: generateContext.runtime,
|
|
runtimeRequirements: generateContext.runtimeRequirements,
|
|
concatenationScope: generateContext.concatenationScope,
|
|
codeGenerationResults:
|
|
/** @type {NonNullable<GenerateContext["codeGenerationResults"]>} */
|
|
(generateContext.codeGenerationResults),
|
|
initFragments,
|
|
get chunkInitFragments() {
|
|
if (!chunkInitFragments) {
|
|
const data =
|
|
/** @type {NonNullable<GenerateContext["getData"]>} */
|
|
(generateContext.getData)();
|
|
chunkInitFragments = data.get("chunkInitFragments");
|
|
if (!chunkInitFragments) {
|
|
chunkInitFragments = [];
|
|
data.set("chunkInitFragments", chunkInitFragments);
|
|
}
|
|
}
|
|
|
|
return chunkInitFragments;
|
|
}
|
|
};
|
|
|
|
template.apply(dependency, source, templateContext);
|
|
|
|
// TODO remove in webpack 6
|
|
if ("getInitFragments" in template) {
|
|
const fragments = deprecatedGetInitFragments(
|
|
template,
|
|
dependency,
|
|
templateContext
|
|
);
|
|
|
|
if (fragments) {
|
|
for (const fragment of fragments) {
|
|
initFragments.push(fragment);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = JavascriptGenerator;
|