flow like the river

This commit is contained in:
root 2025-11-07 00:06:12 +01:00
commit 013fe673f3
42435 changed files with 5764238 additions and 0 deletions

View file

@ -0,0 +1,178 @@
"use strict";
const types = require('@babel/types');
const template = require('@babel/template').default;
const traverse = require('@babel/traverse').default;
const urlJoin = require('../utils/urlJoin');
const isURL = require('../utils/is-url');
const nodeBuiltins = require('node-libs-browser');
const requireTemplate = template('require("_bundle_loader")');
const argTemplate = template('require.resolve(MODULE)');
const serviceWorkerPattern = ['navigator', 'serviceWorker', 'register'];
module.exports = {
ImportDeclaration(node, asset) {
asset.isES6Module = true;
addDependency(asset, node.source);
},
ExportNamedDeclaration(node, asset) {
asset.isES6Module = true;
if (node.source) {
addDependency(asset, node.source);
}
},
ExportAllDeclaration(node, asset) {
asset.isES6Module = true;
addDependency(asset, node.source);
},
ExportDefaultDeclaration(node, asset) {
asset.isES6Module = true;
},
CallExpression(node, asset, ancestors) {
let callee = node.callee,
args = node.arguments;
let isRequire = types.isIdentifier(callee) && callee.name === 'require' && args.length === 1 && types.isStringLiteral(args[0]) && !hasBinding(ancestors, 'require') && !isInFalsyBranch(ancestors);
if (isRequire) {
let optional = ancestors.some(a => types.isTryStatement(a)) || undefined;
addDependency(asset, args[0], {
optional
});
return;
}
let isDynamicImport = callee.type === 'Import' && args.length === 1 && types.isStringLiteral(args[0]);
if (isDynamicImport) {
if (isURL(args[0].value)) return;
asset.addDependency('_bundle_loader');
addDependency(asset, args[0], {
dynamic: true
});
node.callee = requireTemplate().expression;
node.arguments[0] = argTemplate({
MODULE: args[0]
}).expression;
asset.isAstDirty = true;
return;
}
const isRegisterServiceWorker = types.isStringLiteral(args[0]) && types.matchesPattern(callee, serviceWorkerPattern);
if (isRegisterServiceWorker) {
// Treat service workers as an entry point so filenames remain consistent across builds.
// https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#avoid_changing_the_url_of_your_service_worker_script
addURLDependency(asset, args[0], {
entry: true,
isolated: true
});
return;
}
},
NewExpression(node, asset) {
const callee = node.callee,
args = node.arguments;
const isWebWorker = callee.type === 'Identifier' && (callee.name === 'Worker' || callee.name === 'SharedWorker') && args.length === 1 && types.isStringLiteral(args[0]);
if (isWebWorker) {
addURLDependency(asset, args[0], {
isolated: true
});
return;
}
}
};
function hasBinding(node, name) {
if (Array.isArray(node)) {
return node.some(ancestor => hasBinding(ancestor, name));
} else if (types.isProgram(node) || types.isBlockStatement(node) || types.isBlock(node)) {
return node.body.some(statement => hasBinding(statement, name));
} else if (types.isFunctionDeclaration(node) || types.isFunctionExpression(node) || types.isArrowFunctionExpression(node)) {
return node.id && node.id.name === name || node.params.some(param => types.isIdentifier(param) && param.name === name);
} else if (types.isVariableDeclaration(node)) {
return node.declarations.some(declaration => declaration.id.name === name);
}
return false;
}
function isInFalsyBranch(ancestors) {
// Check if any ancestors are if statements
return ancestors.some((node, index) => {
if (types.isIfStatement(node)) {
let res = evaluateExpression(node.test);
if (res && res.confident) {
// If the test is truthy, exclude the dep if it is in the alternate branch.
// If the test if falsy, exclude the dep if it is in the consequent branch.
let child = ancestors[index + 1];
return res.value ? child === node.alternate : child === node.consequent;
}
}
});
}
function evaluateExpression(node) {
// Wrap the node in a standalone program so we can traverse it
node = types.file(types.program([types.expressionStatement(node)])); // Find the first expression and evaluate it.
let res = null;
traverse(node, {
Expression(path) {
res = path.evaluate();
path.stop();
}
});
return res;
}
function addDependency(asset, node, opts = {}) {
// Don't bundle node builtins
if (asset.options.target === 'node' && node.value in nodeBuiltins) {
return;
} // If this came from an inline <script> tag, throw an error.
// TODO: run JSPackager on inline script tags.
let inlineHTML = asset.options.rendition && asset.options.rendition.inlineHTML;
if (inlineHTML) {
let err = new Error('Imports and requires are not supported inside inline <script> tags yet.');
err.loc = node.loc && node.loc.start;
throw err;
}
if (!asset.options.bundleNodeModules) {
const isRelativeImport = /^[/~.]/.test(node.value);
if (!isRelativeImport) return;
}
opts.loc = node.loc && node.loc.start;
asset.addDependency(node.value, opts);
}
function addURLDependency(asset, node, opts = {}) {
opts.loc = node.loc && node.loc.start;
let assetPath = asset.addURLDependency(node.value, opts);
if (!isURL(assetPath)) {
assetPath = urlJoin(asset.options.publicURL, assetPath);
}
node.value = assetPath;
asset.isAstDirty = true;
}

34
BACK_BACK/node_modules/parcel-bundler/lib/visitors/env.js generated vendored Executable file
View file

@ -0,0 +1,34 @@
"use strict";
const types = require('@babel/types');
module.exports = {
MemberExpression(node, asset) {
// Inline environment variables accessed on process.env
if (types.matchesPattern(node.object, 'process.env')) {
let key = types.toComputedKey(node);
if (types.isStringLiteral(key)) {
let prop = process.env[key.value];
if (typeof prop !== 'function') {
let value = types.valueToNode(prop);
morph(node, value);
asset.isAstDirty = true;
asset.cacheData.env[key.value] = process.env[key.value];
}
}
}
}
}; // replace object properties
function morph(object, newProperties) {
for (let key in object) {
delete object[key];
}
for (let key in newProperties) {
object[key] = newProperties[key];
}
}

192
BACK_BACK/node_modules/parcel-bundler/lib/visitors/fs.js generated vendored Executable file
View file

@ -0,0 +1,192 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
const t = require('@babel/types');
const Path = require('path');
const fs = require('fs');
const template = require('@babel/template').default;
const logger = require('@parcel/logger');
const bufferTemplate = template('Buffer(CONTENT, ENC)');
module.exports = {
AssignmentExpression(path) {
if (!isRequire(path.node.right, 'fs', 'readFileSync')) {
return;
}
for (let name in path.getBindingIdentifiers()) {
const binding = path.scope.getBinding(name);
if (!binding) continue;
binding.path.setData('__require', path.node);
}
},
CallExpression(path, asset) {
if (referencesImport(path, 'fs', 'readFileSync')) {
let vars = {
__dirname: Path.dirname(asset.name),
__filename: asset.basename
};
let filename, args, res;
try {
var _path$get$map = path.get('arguments').map(arg => evaluate(arg, vars));
var _path$get$map2 = (0, _toArray2.default)(_path$get$map);
filename = _path$get$map2[0];
args = _path$get$map2.slice(1);
filename = Path.resolve(filename);
res = fs.readFileSync(filename, ...args);
} catch (err) {
if (err instanceof NodeNotEvaluatedError) {
// Warn using a code frame
err.fileName = asset.name;
asset.generateErrorMessage(err);
logger.warn(err);
return;
} // Add location info so we log a code frame with the error
err.loc = path.node.arguments.length > 0 ? path.node.arguments[0].loc.start : path.node.loc.start;
throw err;
}
let replacementNode;
if (Buffer.isBuffer(res)) {
replacementNode = bufferTemplate({
CONTENT: t.stringLiteral(res.toString('base64')),
ENC: t.stringLiteral('base64')
});
} else {
replacementNode = t.stringLiteral(res);
}
asset.addDependency(filename, {
includedInParent: true
});
path.replaceWith(replacementNode);
asset.isAstDirty = true;
}
}
};
function isRequire(node, name, method) {
// e.g. require('fs').readFileSync
if (t.isMemberExpression(node) && node.property.name === method) {
node = node.object;
}
if (!t.isCallExpression(node)) {
return false;
}
let _node = node,
callee = _node.callee,
args = _node.arguments;
let isRequire = t.isIdentifier(callee) && callee.name === 'require' && args.length === 1 && t.isStringLiteral(args[0]);
if (!isRequire) {
return false;
}
if (name && args[0].value !== name) {
return false;
}
return true;
}
function referencesImport(path, name, method) {
let callee = path.node.callee;
let bindingPath; // e.g. readFileSync()
if (t.isIdentifier(callee)) {
bindingPath = getBindingPath(path, callee.name);
} else if (t.isMemberExpression(callee)) {
if (callee.property.name !== method) {
return false;
} // e.g. fs.readFileSync()
if (t.isIdentifier(callee.object)) {
bindingPath = getBindingPath(path, callee.object.name); // require('fs').readFileSync()
} else if (isRequire(callee.object, name)) {
return true;
}
} else {
return false;
}
if (!bindingPath) {
return;
}
let bindingNode = bindingPath.getData('__require') || bindingPath.node;
let parent = bindingPath.parentPath; // e.g. import fs from 'fs';
if (parent.isImportDeclaration()) {
if (bindingPath.isImportSpecifier() && bindingPath.node.imported.name !== method) {
return false;
}
return parent.node.source.value === name; // e.g. var fs = require('fs');
} else if (t.isVariableDeclarator(bindingNode) || t.isAssignmentExpression(bindingNode)) {
let left = bindingNode.id || bindingNode.left;
let right = bindingNode.init || bindingNode.right; // e.g. var {readFileSync} = require('fs');
if (t.isObjectPattern(left)) {
let prop = left.properties.find(p => p.value.name === callee.name);
if (!prop || prop.key.name !== method) {
return false;
}
} else if (!t.isIdentifier(left)) {
return false;
}
return isRequire(right, name, method);
}
return false;
}
function getBindingPath(path, name) {
let binding = path.scope.getBinding(name);
return binding && binding.path;
}
function NodeNotEvaluatedError(node) {
this.message = 'Cannot statically evaluate fs argument';
this.node = node;
this.loc = node.loc.start;
}
function evaluate(path, vars) {
// Inline variables
path.traverse({
Identifier: function Identifier(ident) {
let key = ident.node.name;
if (key in vars) {
ident.replaceWith(t.valueToNode(vars[key]));
}
}
});
let res = path.evaluate();
if (!res.confident) {
throw new NodeNotEvaluatedError(path.node);
}
return res.value;
}

View file

@ -0,0 +1,56 @@
"use strict";
const Path = require('path');
const types = require('@babel/types');
const VARS = {
process: asset => {
asset.addDependency('process');
return 'var process = require("process");';
},
global: asset => `var global = arguments[${asset.options.scopeHoist ? 0 : 3}];`,
__dirname: asset => `var __dirname = ${JSON.stringify(Path.dirname(asset.name))};`,
__filename: asset => `var __filename = ${JSON.stringify(asset.name)};`,
Buffer: asset => {
asset.addDependency('buffer');
return 'var Buffer = require("buffer").Buffer;';
},
// Prevent AMD defines from working when loading UMD bundles.
// Ideally the CommonJS check would come before the AMD check, but many
// existing modules do the checks the opposite way leading to modules
// not exporting anything to Parcel.
define: () => 'var define;'
};
module.exports = {
Identifier(node, asset, ancestors) {
let parent = ancestors[ancestors.length - 2];
if (VARS.hasOwnProperty(node.name) && !asset.globals.has(node.name) && types.isReferenced(node, parent)) {
asset.globals.set(node.name, VARS[node.name](asset));
}
},
Declaration(node, asset, ancestors) {
// If there is a global declaration of one of the variables, remove our declaration
let identifiers = types.getBindingIdentifiers(node);
for (let id in identifiers) {
if (VARS.hasOwnProperty(id) && !inScope(ancestors)) {
// Don't delete entirely, so we don't add it again when the declaration is referenced
asset.globals.set(id, '');
}
}
}
};
function inScope(ancestors) {
for (let i = ancestors.length - 2; i >= 0; i--) {
if (types.isScope(ancestors[i]) && !types.isProgram(ancestors[i])) {
return true;
}
}
return false;
}

View file

@ -0,0 +1,21 @@
"use strict";
const t = require('@babel/types');
module.exports = {
MemberExpression(path) {
// Inline process.browser
const isProcess = path.node.object.name === 'process';
const isBrowser = path.node.property.name === 'browser';
const isAssignment = path.parentPath.type === 'AssignmentExpression';
if (isProcess && isBrowser) {
if (isAssignment) {
path.parentPath.remove();
} else {
path.replaceWith(t.booleanLiteral(true));
}
}
}
};