nuxt-nightly 4.1.1-29281685.c73957ae → 4.1.1-29282072.39113ab4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +61 -33
  2. package/package.json +4 -5
package/dist/index.mjs CHANGED
@@ -35,7 +35,6 @@ import { splitByCase, kebabCase, pascalCase, camelCase } from 'scule';
35
35
  import { createUnplugin } from 'unplugin';
36
36
  import { findStaticImports, findExports, parseStaticImport, parseNodeModulePath, lookupNodeModuleSubpath } from 'mlly';
37
37
  import MagicString from 'magic-string';
38
- import { stripLiteral } from 'strip-literal';
39
38
  import { unheadVueComposablesImports } from '@unhead/vue';
40
39
  import { defineUnimportPreset, createUnimport, toExports, scanDirExports } from 'unimport';
41
40
  import { glob } from 'tinyglobby';
@@ -1105,8 +1104,6 @@ function resolveEnd(node) {
1105
1104
  return "fnNode" in node ? node.fnNode.end : node.end;
1106
1105
  }
1107
1106
 
1108
- const INJECTION_RE_TEMPLATE = /\b_ctx\.\$route\b/g;
1109
- const INJECTION_RE_SCRIPT = /\bthis\.\$route\b/g;
1110
1107
  const INJECTION_SINGLE_RE = /\bthis\.\$route\b|\b_ctx\.\$route\b/;
1111
1108
  const RouteInjectionPlugin = (nuxt) => createUnplugin(() => {
1112
1109
  return {
@@ -1117,29 +1114,30 @@ const RouteInjectionPlugin = (nuxt) => createUnplugin(() => {
1117
1114
  },
1118
1115
  transform: {
1119
1116
  filter: {
1120
- code: { include: INJECTION_SINGLE_RE }
1121
- },
1122
- handler(code) {
1123
- if (code.includes("_ctx._.provides[__nuxt_route_symbol") || code.includes("this._.provides[__nuxt_route_symbol")) {
1124
- return;
1117
+ code: {
1118
+ include: INJECTION_SINGLE_RE,
1119
+ exclude: [
1120
+ `_ctx._.provides[__nuxt_route_symbol`,
1121
+ "this._.provides[__nuxt_route_symbol"
1122
+ ]
1125
1123
  }
1126
- let replaced = false;
1124
+ },
1125
+ handler(code, id) {
1127
1126
  const s = new MagicString(code);
1128
- const strippedCode = stripLiteral(code);
1129
- const replaceMatches = (regExp, replacement) => {
1130
- for (const match of strippedCode.matchAll(regExp)) {
1131
- const start = match.index;
1132
- const end = start + match[0].length;
1133
- s.overwrite(start, end, replacement);
1134
- replaced ||= true;
1127
+ parseAndWalk(code, id, (node) => {
1128
+ if (node.type !== "MemberExpression") {
1129
+ return;
1135
1130
  }
1136
- };
1137
- replaceMatches(INJECTION_RE_TEMPLATE, "(_ctx._.provides[__nuxt_route_symbol] || _ctx.$route)");
1138
- replaceMatches(INJECTION_RE_SCRIPT, "(this._.provides[__nuxt_route_symbol] || this.$route)");
1139
- if (replaced) {
1140
- s.prepend("import { PageRouteSymbol as __nuxt_route_symbol } from '#app/components/injections';\n");
1141
- }
1131
+ if (node.object.type === "ThisExpression" && node.property.type === "Identifier" && node.property.name === "$route") {
1132
+ s.overwrite(node.start, node.end, "(this._.provides[__nuxt_route_symbol] || this.$route)");
1133
+ return;
1134
+ }
1135
+ if (node.object.type === "Identifier" && node.object.name === "_ctx" && node.property.type === "Identifier" && node.property.name === "$route") {
1136
+ s.overwrite(node.start, node.end, "(_ctx._.provides[__nuxt_route_symbol] || _ctx.$route)");
1137
+ }
1138
+ });
1142
1139
  if (s.hasChanged()) {
1140
+ s.prepend("import { PageRouteSymbol as __nuxt_route_symbol } from '#app/components/injections';\n");
1143
1141
  return {
1144
1142
  code: s.toString(),
1145
1143
  map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) : void 0
@@ -3757,7 +3755,7 @@ function addDeclarationTemplates(ctx, options) {
3757
3755
  });
3758
3756
  }
3759
3757
 
3760
- const version = "4.1.1-29281685.c73957ae";
3758
+ const version = "4.1.1-29282072.39113ab4";
3761
3759
 
3762
3760
  const createImportProtectionPatterns = (nuxt, options) => {
3763
3761
  const patterns = [];
@@ -3830,10 +3828,10 @@ const UnctxTransformPlugin = (options) => createUnplugin(() => {
3830
3828
  });
3831
3829
 
3832
3830
  const TreeShakeComposablesPlugin = (options) => createUnplugin(() => {
3833
- const composableNames = Object.values(options.composables).flat();
3834
- const regexp = `(^\\s*)(${composableNames.join("|")})(?=\\((?!\\) \\{))`;
3835
- const COMPOSABLE_RE = new RegExp(regexp, "m");
3836
- const COMPOSABLE_RE_GLOBAL = new RegExp(regexp, "gm");
3831
+ const allComposableNames = new Set(Object.values(options.composables).flat());
3832
+ if (!allComposableNames.size) {
3833
+ return [];
3834
+ }
3837
3835
  return {
3838
3836
  name: "nuxt:tree-shake-composables:transform",
3839
3837
  enforce: "post",
@@ -3842,14 +3840,44 @@ const TreeShakeComposablesPlugin = (options) => createUnplugin(() => {
3842
3840
  },
3843
3841
  transform: {
3844
3842
  filter: {
3845
- code: { include: COMPOSABLE_RE }
3843
+ code: { include: new RegExp(`\\b(?:${[...allComposableNames].map((r) => escapeRE(r)).join("|")})\\b`) }
3846
3844
  },
3847
- handler(code) {
3845
+ handler(code, id) {
3848
3846
  const s = new MagicString(code);
3849
- const strippedCode = stripLiteral(code);
3850
- for (const match of strippedCode.matchAll(COMPOSABLE_RE_GLOBAL)) {
3851
- s.overwrite(match.index, match.index + match[0].length, `${match[1]} false && /*@__PURE__*/ ${match[2]}`);
3852
- }
3847
+ const scopeTracker = new ScopeTracker({ preserveExitedScopes: true });
3848
+ const parseResult = parseAndWalk(code, id, {
3849
+ scopeTracker
3850
+ });
3851
+ scopeTracker.freeze();
3852
+ walk(parseResult.program, {
3853
+ scopeTracker,
3854
+ enter(node) {
3855
+ if (node.type !== "CallExpression" || node.callee.type !== "Identifier") {
3856
+ return;
3857
+ }
3858
+ const functionName = node.callee.name;
3859
+ const scopeTrackerNode = scopeTracker.getDeclaration(functionName);
3860
+ if (scopeTrackerNode) {
3861
+ if (scopeTrackerNode.type !== "Import") {
3862
+ return;
3863
+ }
3864
+ if (scopeTrackerNode.importNode.type !== "ImportDeclaration") {
3865
+ return;
3866
+ }
3867
+ const importPath = scopeTrackerNode.importNode.source.value;
3868
+ const importSpecifier = scopeTrackerNode.node;
3869
+ const importedName = importSpecifier.type === "ImportSpecifier" && importSpecifier.imported.type === "Identifier" ? importSpecifier.imported.name : importSpecifier.local.name;
3870
+ const isFromAllowedPath = importPath === "#imports" ? allComposableNames.has(importedName) : options.composables[importPath]?.includes(importedName);
3871
+ if (!isFromAllowedPath) {
3872
+ return;
3873
+ }
3874
+ }
3875
+ if (!scopeTrackerNode && !allComposableNames.has(functionName)) {
3876
+ return;
3877
+ }
3878
+ s.overwrite(node.start, node.end, ` false && /*@__PURE__*/ ${functionName}${code.slice(node.callee.end, node.end)}`);
3879
+ }
3880
+ });
3853
3881
  if (s.hasChanged()) {
3854
3882
  return {
3855
3883
  code: s.toString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-nightly",
3
- "version": "4.1.1-29281685.c73957ae",
3
+ "version": "4.1.1-29282072.39113ab4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -67,10 +67,10 @@
67
67
  "@nuxt/cli": "npm:@nuxt/cli-nightly@latest",
68
68
  "@nuxt/devalue": "^2.0.2",
69
69
  "@nuxt/devtools": "^2.6.3",
70
- "@nuxt/kit": "npm:@nuxt/kit-nightly@4.1.1-29281685.c73957ae",
71
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.1.1-29281685.c73957ae",
70
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@4.1.1-29282072.39113ab4",
71
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.1.1-29282072.39113ab4",
72
72
  "@nuxt/telemetry": "^2.6.6",
73
- "@nuxt/vite-builder": "npm:@nuxt/vite-builder-nightly@4.1.1-29281685.c73957ae",
73
+ "@nuxt/vite-builder": "npm:@nuxt/vite-builder-nightly@4.1.1-29282072.39113ab4",
74
74
  "@unhead/vue": "^2.0.14",
75
75
  "@vue/shared": "^3.5.20",
76
76
  "c12": "^3.2.0",
@@ -113,7 +113,6 @@
113
113
  "scule": "^1.3.0",
114
114
  "semver": "^7.7.2",
115
115
  "std-env": "^3.9.0",
116
- "strip-literal": "^3.0.0",
117
116
  "tinyglobby": "0.2.14",
118
117
  "ufo": "^1.6.1",
119
118
  "ultrahtml": "^1.6.0",