vite-plugin-taro 0.6.1 → 0.6.2

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 (47) hide show
  1. package/dist/node/plugins/h5/transform-app.js +1 -1
  2. package/dist/node/plugins/wx/dev/plugins.js +1 -1
  3. package/dist/node/plugins/wx/dev/wx-dev-options.js +1 -1
  4. package/dist/node/plugins/wx/{module.js → module/module.js} +2 -2
  5. package/dist/node/plugins/wx/placer/placement.d.ts +1 -0
  6. package/dist/node/plugins/wx/placer/placement.js +1 -1
  7. package/dist/node/plugins/wx/placer/placer.d.ts +17 -1
  8. package/dist/node/plugins/wx/placer/placer.js +25 -1
  9. package/dist/node/plugins/wx/plugins.js +1 -1
  10. package/dist/node/plugins/wx/render/capsule.d.ts +35 -3
  11. package/dist/node/plugins/wx/render/capsule.js +53 -12
  12. package/dist/node/plugins/wx/render/native.d.ts +20 -2
  13. package/dist/node/plugins/wx/render/native.js +539 -35
  14. package/dist/node/plugins/wx/render/system-js/string-editor.d.ts +24 -0
  15. package/dist/node/plugins/wx/render/system-js/string-editor.js +93 -0
  16. package/dist/node/plugins/wx/render/system-js/system-js.d.ts +23 -0
  17. package/dist/node/plugins/wx/render/system-js/system-js.js +602 -0
  18. package/dist/node/plugins/wx/render/transport.js +3 -3
  19. package/dist/node/plugins/wx/resolve/resolver.js +1 -1
  20. package/dist/node/plugins/wx/resolve/specialize-bootstrap.js +1 -1
  21. package/dist/node/plugins/wx/resolve/specialize-page-capsule.js +1 -1
  22. package/dist/node/utils/transform.d.ts +0 -3
  23. package/dist/node/utils/transform.js +0 -23
  24. package/package.json +8 -6
  25. package/src/node/plugins/h5/transform-app.ts +1 -1
  26. package/src/node/plugins/wx/dev/plugins.ts +1 -1
  27. package/src/node/plugins/wx/dev/wx-dev-options.ts +1 -1
  28. package/src/node/plugins/wx/{module.ts → module/module.ts} +2 -2
  29. package/src/node/plugins/wx/placer/placement.ts +1 -1
  30. package/src/node/plugins/wx/placer/placer.ts +27 -2
  31. package/src/node/plugins/wx/plugins.ts +1 -1
  32. package/src/node/plugins/wx/render/capsule.ts +53 -17
  33. package/src/node/plugins/wx/render/native.ts +670 -55
  34. package/src/node/plugins/wx/render/system-js/string-editor.ts +115 -0
  35. package/src/node/plugins/wx/render/system-js/system-js.ts +831 -0
  36. package/src/node/plugins/wx/render/transport.ts +3 -3
  37. package/src/node/plugins/wx/resolve/resolver.ts +1 -1
  38. package/src/node/plugins/wx/resolve/specialize-bootstrap.ts +1 -1
  39. package/src/node/plugins/wx/resolve/specialize-page-capsule.ts +1 -1
  40. package/src/node/utils/transform.ts +0 -30
  41. package/dist/node/plugins/wx/render/capsule-wrapper.d.ts +0 -3
  42. package/dist/node/plugins/wx/render/capsule-wrapper.js +0 -64
  43. package/src/node/plugins/wx/render/capsule-wrapper.ts +0 -86
  44. /package/dist/node/plugins/wx/{chunk-path.d.ts → module/chunk-path.d.ts} +0 -0
  45. /package/dist/node/plugins/wx/{chunk-path.js → module/chunk-path.js} +0 -0
  46. /package/dist/node/plugins/wx/{module.d.ts → module/module.d.ts} +0 -0
  47. /package/src/node/plugins/wx/{chunk-path.ts → module/chunk-path.ts} +0 -0
@@ -0,0 +1,115 @@
1
+ /** One half-open source range replaced atomically during rendering. */
2
+ type Replacement = Readonly<{
3
+ content: string
4
+ end: number
5
+ start: number
6
+ }>
7
+
8
+ /** Ordered zero-width edits attached to one source boundary. */
9
+ type Insertions = Readonly<{
10
+ append: string[]
11
+ prepend: string[]
12
+ }>
13
+
14
+ /**
15
+ * Records non-overlapping range edits and renders them in one source-order pass.
16
+ *
17
+ * Final WX development chunks do not request source maps. RolldownMagicString's repeated relocation of hundreds of hoisted
18
+ * functions is considerably more expensive than the semantic analysis itself, so this editor keeps the same range operations
19
+ * while avoiding a mutable chunk graph when no mappings can be observed.
20
+ */
21
+ export class StringEditor {
22
+ readonly original: string
23
+ // These journals are the editor's intentionally mutable transaction; rendering reads but never changes them.
24
+ readonly #insertions = new Map<number, Insertions>()
25
+ readonly #replacements: Replacement[] = []
26
+
27
+ constructor(original: string) {
28
+ this.original = original
29
+ }
30
+
31
+ /** Records a half-open replacement; semantic passes guarantee ranges are nested or disjoint. */
32
+ overwrite(start: number, end: number, content: string): void {
33
+ this.#replacements.push({ content, end, start })
34
+ }
35
+
36
+ /** Removes a range and discards insertions that were owned only by that removed source. */
37
+ remove(start: number, end: number): void {
38
+ this.overwrite(start, end, '')
39
+ // Removed ranges own their boundary insertions; hoisted function text has already rendered those edits separately.
40
+ for (const position of this.#insertions.keys()) {
41
+ if (position >= start && position <= end) this.#insertions.delete(position)
42
+ }
43
+ }
44
+
45
+ /** Inserts before prior insertions at a boundary, matching MagicString's prependLeft ordering. */
46
+ prependLeft(position: number, content: string): void {
47
+ const insertions = this.#insertionAt(position)
48
+ insertions.prepend.unshift(content)
49
+ }
50
+
51
+ /** Inserts after prior insertions at the left side of a boundary. */
52
+ appendLeft(position: number, content: string): void {
53
+ const insertions = this.#insertionAt(position)
54
+ insertions.append.push(content)
55
+ }
56
+
57
+ /** Matches the subset of appendRight ordering used by the capsule compiler. */
58
+ appendRight(position: number, content: string): void {
59
+ const insertions = this.#insertionAt(position)
60
+ insertions.append.push(content)
61
+ }
62
+
63
+ /** Materializes one source slice without mutating its edit journal, allowing functions to be rendered before relocation. */
64
+ render(start: number, end: number): string {
65
+ const replacements = this.#replacements
66
+ .filter((replacement) => replacement.start >= start && replacement.end <= end)
67
+ .sort((left, right) => left.start - right.start || right.end - left.end)
68
+ // The cursor advances monotonically; outer removals dominate nested edits when hoisted function ranges are removed.
69
+ let sourcePosition = start
70
+ let output = ''
71
+
72
+ for (const replacement of replacements) {
73
+ if (replacement.end <= sourcePosition) continue
74
+ if (replacement.start < sourcePosition) {
75
+ throw new Error(`Partially overlapping source edits at ${replacement.start}:${replacement.end}`)
76
+ }
77
+ output += this.#renderOriginal(sourcePosition, replacement.start, false)
78
+ output += replacement.content
79
+ sourcePosition = replacement.end
80
+ }
81
+
82
+ output += this.#renderOriginal(sourcePosition, end, true)
83
+ return output
84
+ }
85
+
86
+ #insertionAt(position: number): { append: string[]; prepend: string[] } {
87
+ const existing = this.#insertions.get(position)
88
+ if (existing) return existing
89
+ // Each position owns mutable ordered lists because prependLeft reverses calls while appendRight preserves them.
90
+ const created = { append: [], prepend: [] }
91
+ this.#insertions.set(position, created)
92
+ return created
93
+ }
94
+
95
+ #renderOriginal(start: number, end: number, includeEnd: boolean): string {
96
+ const positions = [...this.#insertions.keys()]
97
+ .filter((position) => position >= start && (position < end || (includeEnd && position === end)))
98
+ .sort((left, right) => left - right)
99
+ // Segment rendering appends immutable source slices around the small ordered insertion set.
100
+ let sourcePosition = start
101
+ let output = ''
102
+ for (const position of positions) {
103
+ output += this.original.slice(sourcePosition, position)
104
+ output += this.#renderInsertions(position)
105
+ sourcePosition = position
106
+ }
107
+ output += this.original.slice(sourcePosition, end)
108
+ return output
109
+ }
110
+
111
+ #renderInsertions(position: number): string {
112
+ const insertions = this.#insertions.get(position)
113
+ return insertions ? `${insertions.prepend.join('')}${insertions.append.join('')}` : ''
114
+ }
115
+ }