版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chunk-IWTTFLP7.js 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true});
  2. var _chunkYNXVNEEBjs = require('./chunk-YNXVNEEB.js');
  3. var _chunkCDFZGZHMjs = require('./chunk-CDFZGZHM.js');
  4. // src/ast.ts
  5. var _compilersfc = require('@vue/compiler-sfc');
  6. // ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
  7. var WalkerBase = class {
  8. constructor() {
  9. this.should_skip = false;
  10. this.should_remove = false;
  11. this.replacement = null;
  12. this.context = {
  13. skip: () => this.should_skip = true,
  14. remove: () => this.should_remove = true,
  15. replace: (node) => this.replacement = node
  16. };
  17. }
  18. /**
  19. * @template {Node} Parent
  20. * @param {Parent | null | undefined} parent
  21. * @param {keyof Parent | null | undefined} prop
  22. * @param {number | null | undefined} index
  23. * @param {Node} node
  24. */
  25. replace(parent, prop, index, node) {
  26. if (parent && prop) {
  27. if (index != null) {
  28. parent[prop][index] = node;
  29. } else {
  30. parent[prop] = node;
  31. }
  32. }
  33. }
  34. /**
  35. * @template {Node} Parent
  36. * @param {Parent | null | undefined} parent
  37. * @param {keyof Parent | null | undefined} prop
  38. * @param {number | null | undefined} index
  39. */
  40. remove(parent, prop, index) {
  41. if (parent && prop) {
  42. if (index !== null && index !== void 0) {
  43. parent[prop].splice(index, 1);
  44. } else {
  45. delete parent[prop];
  46. }
  47. }
  48. }
  49. };
  50. // ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
  51. var SyncWalker = class extends WalkerBase {
  52. /**
  53. *
  54. * @param {SyncHandler} [enter]
  55. * @param {SyncHandler} [leave]
  56. */
  57. constructor(enter, leave) {
  58. super();
  59. this.should_skip = false;
  60. this.should_remove = false;
  61. this.replacement = null;
  62. this.context = {
  63. skip: () => this.should_skip = true,
  64. remove: () => this.should_remove = true,
  65. replace: (node) => this.replacement = node
  66. };
  67. this.enter = enter;
  68. this.leave = leave;
  69. }
  70. /**
  71. * @template {Node} Parent
  72. * @param {Node} node
  73. * @param {Parent | null} parent
  74. * @param {keyof Parent} [prop]
  75. * @param {number | null} [index]
  76. * @returns {Node | null}
  77. */
  78. visit(node, parent, prop, index) {
  79. if (node) {
  80. if (this.enter) {
  81. const _should_skip = this.should_skip;
  82. const _should_remove = this.should_remove;
  83. const _replacement = this.replacement;
  84. this.should_skip = false;
  85. this.should_remove = false;
  86. this.replacement = null;
  87. this.enter.call(this.context, node, parent, prop, index);
  88. if (this.replacement) {
  89. node = this.replacement;
  90. this.replace(parent, prop, index, node);
  91. }
  92. if (this.should_remove) {
  93. this.remove(parent, prop, index);
  94. }
  95. const skipped = this.should_skip;
  96. const removed = this.should_remove;
  97. this.should_skip = _should_skip;
  98. this.should_remove = _should_remove;
  99. this.replacement = _replacement;
  100. if (skipped)
  101. return node;
  102. if (removed)
  103. return null;
  104. }
  105. let key;
  106. for (key in node) {
  107. const value = node[key];
  108. if (value && typeof value === "object") {
  109. if (Array.isArray(value)) {
  110. const nodes = (
  111. /** @type {Array<unknown>} */
  112. value
  113. );
  114. for (let i = 0; i < nodes.length; i += 1) {
  115. const item = nodes[i];
  116. if (isNode(item)) {
  117. if (!this.visit(item, node, key, i)) {
  118. i--;
  119. }
  120. }
  121. }
  122. } else if (isNode(value)) {
  123. this.visit(value, node, key, null);
  124. }
  125. }
  126. }
  127. if (this.leave) {
  128. const _replacement = this.replacement;
  129. const _should_remove = this.should_remove;
  130. this.replacement = null;
  131. this.should_remove = false;
  132. this.leave.call(this.context, node, parent, prop, index);
  133. if (this.replacement) {
  134. node = this.replacement;
  135. this.replace(parent, prop, index, node);
  136. }
  137. if (this.should_remove) {
  138. this.remove(parent, prop, index);
  139. }
  140. const removed = this.should_remove;
  141. this.replacement = _replacement;
  142. this.should_remove = _should_remove;
  143. if (removed)
  144. return null;
  145. }
  146. }
  147. return node;
  148. }
  149. };
  150. function isNode(value) {
  151. return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
  152. }
  153. // ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
  154. function walk(ast, { enter, leave }) {
  155. const instance = new SyncWalker(enter, leave);
  156. return instance.visit(ast, null);
  157. }
  158. // src/ast.ts
  159. function babelParse(code, lang, options = {}) {
  160. const plugins = [...options.plugins || []];
  161. if (_chunkYNXVNEEBjs.isTs.call(void 0, lang)) {
  162. plugins.push(["typescript", { dts: lang === "dts" }]);
  163. if (_chunkCDFZGZHMjs.REGEX_LANG_JSX.test(lang))
  164. plugins.push("jsx");
  165. if (!plugins.includes("decorators"))
  166. plugins.push("decorators-legacy");
  167. } else {
  168. plugins.push("jsx");
  169. }
  170. const { program } = _compilersfc.babelParse.call(void 0, code, {
  171. sourceType: "module",
  172. plugins,
  173. ...options
  174. });
  175. return program;
  176. }
  177. function isCallOf(node, test) {
  178. return !!(node && node.type === "CallExpression" && node.callee.type === "Identifier" && (typeof test === "string" ? node.callee.name === test : Array.isArray(test) ? test.includes(node.callee.name) : test(node.callee.name)));
  179. }
  180. function checkInvalidScopeReference(node, method, setupBindings) {
  181. if (!node)
  182. return;
  183. _compilersfc.walkIdentifiers.call(void 0, node, (id) => {
  184. if (setupBindings.includes(id.name))
  185. throw new SyntaxError(
  186. `\`${method}()\` in <script setup> cannot reference locally declared variables (${id.name}) because it will be hoisted outside of the setup() function.`
  187. );
  188. });
  189. }
  190. function isStaticExpression(node, options = {}) {
  191. var _a;
  192. const { magicComment, fn, object, objectMethod, array, unary } = options;
  193. if (magicComment && ((_a = node.leadingComments) == null ? void 0 : _a.some(
  194. (comment) => comment.value.trim() === magicComment
  195. )))
  196. return true;
  197. else if (fn && isFunctionType(node))
  198. return true;
  199. switch (node.type) {
  200. case "UnaryExpression":
  201. return !!unary && isStaticExpression(node.argument, options);
  202. case "LogicalExpression":
  203. case "BinaryExpression":
  204. return isStaticExpression(node.left, options) && isStaticExpression(node.right, options);
  205. case "ConditionalExpression":
  206. return isStaticExpression(node.test, options) && isStaticExpression(node.consequent, options) && isStaticExpression(node.alternate, options);
  207. case "SequenceExpression":
  208. case "TemplateLiteral":
  209. return node.expressions.every((expr) => isStaticExpression(expr, options));
  210. case "ArrayExpression":
  211. return !!array && node.elements.every(
  212. (element) => element && isStaticExpression(element, options)
  213. );
  214. case "ObjectExpression":
  215. return !!object && node.properties.every((prop) => {
  216. if (prop.type === "SpreadElement") {
  217. return prop.argument.type === "ObjectExpression" && isStaticExpression(prop.argument, options);
  218. } else if (!isLiteralType(prop.key) && prop.computed) {
  219. return false;
  220. } else if (prop.type === "ObjectProperty" && !isStaticExpression(prop.value, options)) {
  221. return false;
  222. }
  223. if (prop.type === "ObjectMethod" && !objectMethod) {
  224. return false;
  225. }
  226. return true;
  227. });
  228. case "ParenthesizedExpression":
  229. case "TSNonNullExpression":
  230. case "TSAsExpression":
  231. case "TSTypeAssertion":
  232. return isStaticExpression(node.expression, options);
  233. }
  234. if (isLiteralType(node))
  235. return true;
  236. return false;
  237. }
  238. function isLiteralType(node) {
  239. return node.type.endsWith("Literal");
  240. }
  241. function resolveTemplateLiteral(node) {
  242. return node.quasis.reduce((prev, curr, idx) => {
  243. if (node.expressions[idx]) {
  244. return prev + curr.value.cooked + resolveLiteral(node.expressions[idx]);
  245. }
  246. return prev + curr.value.cooked;
  247. }, "");
  248. }
  249. function resolveLiteral(node) {
  250. switch (node.type) {
  251. case "TemplateLiteral":
  252. return resolveTemplateLiteral(node);
  253. case "NullLiteral":
  254. return null;
  255. case "BigIntLiteral":
  256. return BigInt(node.value);
  257. case "RegExpLiteral":
  258. return new RegExp(node.pattern, node.flags);
  259. case "BooleanLiteral":
  260. case "NumericLiteral":
  261. case "StringLiteral":
  262. return node.value;
  263. }
  264. return void 0;
  265. }
  266. function isStaticObjectKey(node) {
  267. return node.properties.every((prop) => {
  268. if (prop.type === "SpreadElement") {
  269. return prop.argument.type === "ObjectExpression" && isStaticObjectKey(prop.argument);
  270. }
  271. return !prop.computed || isLiteralType(prop.key);
  272. });
  273. }
  274. function resolveObjectExpression(node) {
  275. const maps = {};
  276. for (const property of node.properties) {
  277. if (property.type === "SpreadElement") {
  278. if (property.argument.type !== "ObjectExpression")
  279. return void 0;
  280. Object.assign(maps, resolveObjectExpression(property.argument));
  281. } else {
  282. const key = resolveObjectKey(property.key, property.computed, false);
  283. maps[key] = property;
  284. }
  285. }
  286. return maps;
  287. }
  288. function resolveObjectKey(node, computed = false, raw = true) {
  289. switch (node.type) {
  290. case "StringLiteral":
  291. case "NumericLiteral":
  292. return raw ? node.extra.raw : node.value;
  293. case "Identifier":
  294. if (!computed)
  295. return raw ? `'${node.name}'` : node.name;
  296. default:
  297. throw new SyntaxError(`Unexpected node type: ${node.type}`);
  298. }
  299. }
  300. function walkAST(node, options) {
  301. return walk(node, options);
  302. }
  303. function isFunctionType(node) {
  304. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  305. }
  306. var TS_NODE_TYPES = [
  307. "TSAsExpression",
  308. // foo as number
  309. "TSTypeAssertion",
  310. // (<number>foo)
  311. "TSNonNullExpression",
  312. // foo!
  313. "TSInstantiationExpression",
  314. // foo<string>
  315. "TSSatisfiesExpression"
  316. // foo satisfies T
  317. ];
  318. function unwrapTSNode(node) {
  319. if (TS_NODE_TYPES.includes(node.type)) {
  320. return unwrapTSNode(node.expression);
  321. } else {
  322. return node;
  323. }
  324. }
  325. exports.babelParse = babelParse; exports.isCallOf = isCallOf; exports.checkInvalidScopeReference = checkInvalidScopeReference; exports.isStaticExpression = isStaticExpression; exports.isLiteralType = isLiteralType; exports.resolveTemplateLiteral = resolveTemplateLiteral; exports.resolveLiteral = resolveLiteral; exports.isStaticObjectKey = isStaticObjectKey; exports.resolveObjectExpression = resolveObjectExpression; exports.resolveObjectKey = resolveObjectKey; exports.walkAST = walkAST; exports.isFunctionType = isFunctionType; exports.TS_NODE_TYPES = TS_NODE_TYPES; exports.unwrapTSNode = unwrapTSNode;