Repository navigation
perf(compiler): faster and more accurate source maps - #16126
johnsoncodehk wants to merge 42 commits into
Conversation
EditedString has the API and types of the existing string-editing export. muggle-string renders its text and source maps; the maps follow muggle-string's rules, so generated code maps to the source it came from and inserted code maps to nothing. muggle-string 1.0.2 is exempted from minimumReleaseAge, as it was published today.
compiler-sfc edits and exports EditedString in place of the existing string-editing export, under the same name and types, and no longer depends on it.
In inline mode, the script map is taken decoded from EditedString, the template map is read once with source-map-js, and the merged segments are written with encodeMappings of muggle-string, in the order and with the duplicates dropped that the source-map-js generator gives them. compiler-sfc no longer goes through the generator for the merge.
With sourceMap false, compileScript passes sourceMap false to the inline compileTemplate, so no template map is generated only to be dropped.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/compiler-vapor
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/runtime-vapor
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Size ReportBundles
Usages
|
|
It seems 4 of the failures are related to this PR.
|
* build: use muggle-string with decodeMappings * refactor(compiler-sfc): build block maps from segments * refactor(compiler-sfc): remap template lines by segments * refactor(compiler-sfc): decode the inlined template map * refactor(compiler-core): build source maps from segments * build(compiler-sfc): remove source-map-js dependency * build: use muggle-string 1.0.3 * perf(compiler): cache decoded source map segments to avoid redundant decoding Store decoded segments in WeakMap when encoding source maps, and retrieve them when decoding to skip repeated decodeMappings calls. The cache is owned by Vue's encoder side (compiler-core and compiler-sfc) and keyed by the encoded map object. Consumers check the cache first and fall back to decodeMappings on cache miss, so external maps still work. Cache lives in: - compiler-core/src/sourcemap.ts for maps from template codegen - compiler-sfc/src/sourcemap.ts for maps from parse and transformations Maps flow decoded through the pipeline: - parse.ts generateSourceMap encodes + caches - codegen.ts toJSON encodes + caches - compileTemplate.ts mapLines uses cache + re-caches result - compileScript.ts mergeSourceMaps uses cache + re-caches result Parse cache preserves map object identity, so cached descriptors benefit from segment reuse across multiple compileTemplate calls. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * build: use muggle-string 1.0.2 Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler): keep decoded segments of Vue encoded maps in one WeakMap Source maps now travel decoded through the compiler and are only encoded when written. Every map Vue encodes registers its segments in the `decodedMappings` WeakMap exported by @vue/compiler-core (and re-exported by @vue/compiler-sfc), keyed by the map object, so consumers read the segments instead of decoding them. Nothing in Vue decodes mappings anymore: the inMap of compileTemplate and the template map merged by compileScript must be maps Vue encoded, and any other map now throws. This replaces the two duplicate caches in compiler-core and compiler-sfc and their decode fallbacks, and restores mapLines returning oldMap when there is no newMap. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler): keep codegen source map segments on the context The codegen contexts of compiler-core and compiler-vapor now hold the segments of each generated line and the name indexes directly, added with addMapping, and generate builds the encoded map once at the end with createSourceMap, which registers its segments in decodedMappings. This drops the CodegenSourceMapGenerator object and its addMapping/toJSON methods. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * build: use muggle-string 1.0.3 Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * fix(compiler-sfc): decode source maps Vue did not encode A map from a custom template compiler, or a descriptor map that was serialized or cloned, is not in decodedMappings. Reading such a map is where decoding belongs, so it is decoded with decodeMappings instead of being rejected. Maps Vue encoded are still read from decodedMappings. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler): carry segments on source maps instead of a WeakMap A map Vue builds from segments keeps them in the non-enumerable `_segments`, and its `mappings` is encoded when first read, after which only the string is kept. mapLines and mergeSourceMaps read `_segments` when present and otherwise decode `mappings`. The template block map from parse, which is only read by compileTemplate with inMap and no ast, is encoded right away and keeps no segments. This removes the decodedMappings WeakMap, which kept the segments of every map alive alongside the descriptors that hold them. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * build(compiler-core): keep the source map encoder out of browser builds Browser builds generate no codegen source maps, so defineMappings is a no-op there like createSourceMap, which keeps encodeMappings out of the compiler-dom browser bundles. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler): encode source maps when built and decode when read Every map Vue builds, from parse, codegen, mapLines and mergeSourceMaps, is encoded to a plain string right away and keeps no segments; mapLines and mergeSourceMaps decode mappings with decodeMappings when they need segments. Keeping segments alive on the maps cost more CPU and memory than decoding them again. This removes defineMappings, getSegments and the `_segments` field. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…#19) * build: use muggle-string with decodeMappings * refactor(compiler-sfc): build block maps from segments * refactor(compiler-sfc): remap template lines by segments * refactor(compiler-sfc): decode the inlined template map * refactor(compiler-core): build source maps from segments * build(compiler-sfc): remove source-map-js dependency * build: use muggle-string 1.0.3 * perf(compiler): cache decoded source map segments to avoid redundant decoding Store decoded segments in WeakMap when encoding source maps, and retrieve them when decoding to skip repeated decodeMappings calls. The cache is owned by Vue's encoder side (compiler-core and compiler-sfc) and keyed by the encoded map object. Consumers check the cache first and fall back to decodeMappings on cache miss, so external maps still work. Cache lives in: - compiler-core/src/sourcemap.ts for maps from template codegen - compiler-sfc/src/sourcemap.ts for maps from parse and transformations Maps flow decoded through the pipeline: - parse.ts generateSourceMap encodes + caches - codegen.ts toJSON encodes + caches - compileTemplate.ts mapLines uses cache + re-caches result - compileScript.ts mergeSourceMaps uses cache + re-caches result Parse cache preserves map object identity, so cached descriptors benefit from segment reuse across multiple compileTemplate calls. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * build: use muggle-string 1.0.2 Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler): keep decoded segments of Vue encoded maps in one WeakMap Source maps now travel decoded through the compiler and are only encoded when written. Every map Vue encodes registers its segments in the `decodedMappings` WeakMap exported by @vue/compiler-core (and re-exported by @vue/compiler-sfc), keyed by the map object, so consumers read the segments instead of decoding them. Nothing in Vue decodes mappings anymore: the inMap of compileTemplate and the template map merged by compileScript must be maps Vue encoded, and any other map now throws. This replaces the two duplicate caches in compiler-core and compiler-sfc and their decode fallbacks, and restores mapLines returning oldMap when there is no newMap. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler): keep codegen source map segments on the context The codegen contexts of compiler-core and compiler-vapor now hold the segments of each generated line and the name indexes directly, added with addMapping, and generate builds the encoded map once at the end with createSourceMap, which registers its segments in decodedMappings. This drops the CodegenSourceMapGenerator object and its addMapping/toJSON methods. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * build: use muggle-string 1.0.3 Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * fix(compiler-sfc): decode source maps Vue did not encode A map from a custom template compiler, or a descriptor map that was serialized or cloned, is not in decodedMappings. Reading such a map is where decoding belongs, so it is decoded with decodeMappings instead of being rejected. Maps Vue encoded are still read from decodedMappings. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler): carry segments on source maps instead of a WeakMap A map Vue builds from segments keeps them in the non-enumerable `_segments`, and its `mappings` is encoded when first read, after which only the string is kept. mapLines and mergeSourceMaps read `_segments` when present and otherwise decode `mappings`. The template block map from parse, which is only read by compileTemplate with inMap and no ast, is encoded right away and keeps no segments. This removes the decodedMappings WeakMap, which kept the segments of every map alive alongside the descriptors that hold them. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * build(compiler-core): keep the source map encoder out of browser builds Browser builds generate no codegen source maps, so defineMappings is a no-op there like createSourceMap, which keeps encodeMappings out of the compiler-dom browser bundles. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler): encode source maps when built and decode when read Every map Vue builds, from parse, codegen, mapLines and mergeSourceMaps, is encoded to a plain string right away and keeps no segments; mapLines and mergeSourceMaps decode mappings with decodeMappings when they need segments. Keeping segments alive on the maps cost more CPU and memory than decoding them again. This removes defineMappings, getSegments and the `_segments` field. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * fix(compiler): count the newlines before an identifier in its location The line and column of a prefixed identifier were advanced over the identifier's own text instead of the expression before it, so an identifier after a newline kept the expression's first line and got a column past its end. The offset was right; source maps pointed at the wrong place. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * fix(compiler-vapor): locate the selector of a v-for in the template The selector expression of a createSelector call took the location of its node in the parsed expression, whose line and column count from the expression and which has no offset, so its source map pointed at the start of the template. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler): render template source maps from muggle-string pieces Codegen of compiler-core and compiler-vapor adds a piece per push: the text of a node maps to the node's range, and text without a node maps to the end of the last node on its line, as an empty range. muggle-string renders the map from the pieces, so codegen no longer tracks generated lines and columns, and vapor no longer pads the code with line feeds for its preamble. The maps change where that helps debugging: - the helper calls of an interpolation, a vnode call and a slot map to their node, e.g. `_toDisplayString(` maps to `{{` instead of the end of the element before it - `_ctx.foo` has no name, so a debugger no longer shows the render context `_ctx` as `foo` - code that a newline of the codegen starts maps nowhere instead of holding the last mapping of the line before Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler-sfc): inline the pieces of the render function into the script map In inline mode the pieces of the template map go into the render of the script at the text that holds the render function, so the map of the script is rendered once with both, in place of decoding, merging and sorting two maps. A template compiler that gives only a map has its segments read as pieces. A template map that parse gave for the block is a shift of lines and columns, so its first segment gives the shift, in place of looking up each line. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * fix(compiler-core): map the text call of a text node to its text The createTextVNode call had no location, so a debugger stopping on it fell back to whatever came before it on the line or showed no position. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler-core): map the indentation of a line with the range after it A line indented before a located node wrote an unmapped segment for the indentation and a mapped one for the node. Joined, the line starts with one mapped segment, which finds the same position at any column of the line. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * fix(compiler-vapor): map the display string call of an interpolation to its expression As in the vdom codegen, a debugger stopping on the toDisplayString call of an interpolation now shows the interpolated expression instead of no position. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
* refactor(compiler-sfc): rewrite default exports on a muggle-string rewrite rewriteDefault and the normal script path build a SourceRewrite of the script and render its text, instead of going through EditedString. rewriteDefaultAST now takes that SourceRewrite and reads the original text from its source. The output is unchanged. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler-sfc): compile scripts on a muggle-string rewrite ScriptCompileContext edits the SFC source through a SourceRewrite of muggle-string instead of EditedString. Macros insert with insertBefore and insertAfter, remove with an empty replace, and replace code through ctx.replace, which writes it as a range of the source so that it maps to the code it replaces. Hoisting places a cut at the start of the output. Code that goes in front of earlier code at one position is now built in its final order before it is inserted: the helper imports, the template preamble and the import of a re-exported default before all of the output, and the setup() head, the async temp variables and the css vars code at the start of <script setup>. The output is unchanged. The output and its map are rendered in one pass, with renderWithSourceMap, or renderWithDecodedSourceMap when the template map is merged in, instead of a render for the text and another for the map. The map names the file as given in `sources`, as the block and template maps do. A Windows path used to be written with forward slashes in the script map only, so an inline map listed the same file twice, with its content twice. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler-sfc): remove EditedString Nothing in compiler-sfc edits through EditedString anymore. Remove it, its tests, and its export under the old name, whose users can create a SourceRewrite with muggle-string instead. BREAKING CHANGE: @vue/compiler-sfc no longer exports the string editor that EditedString stood in for. rewriteDefaultAST takes a SourceRewrite of muggle-string, and ScriptCompileContext.s is one. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
❌ Deploy Preview for vue-sfc-playground failed. Why did it fail? →
|
@vue/repl imports a string editor from vue/compiler-sfc, which no longer exports one, so the playground build failed with a missing export. The playground resolves that import to a module that re-exports compiler-sfc with an editor for the methods the module compiler uses. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…ng editor" This reverts commit c472118. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…emapping (#21) * refactor(compiler-sfc): shift template pieces instead of remapping Pieces compiled from the template block are shifted by its offset in the SFC, and codegen takes the caller's source so inline maps check it by identity. Preprocessed templates are left unmapped, since the preprocessor gives no positions. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler-sfc): generate block pieces at their offset in the SFC Codegen takes the offset of the template in the SFC, so the map it renders for a template compiled from the block content is the final one, instead of shifting the pieces and rendering a second map. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
* refactor(compiler-sfc): shift template pieces instead of remapping Pieces compiled from the template block are shifted by its offset in the SFC, and codegen takes the caller's source so inline maps check it by identity. Preprocessed templates are left unmapped, since the preprocessor gives no positions. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler-sfc): generate block pieces at their offset in the SFC Codegen takes the offset of the template in the SFC, so the map it renders for a template compiled from the block content is the final one, instead of shifting the pieces and rendering a second map. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * fix(compiler-core): map text starting a line to the node it is generated in Closing lines such as `]))` carried a segment without a source, so a position on them mapped nowhere. They now map to the end of the node they close. The comment added for a v-if without v-else still maps nowhere. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * fix(compiler-core): map a line to the node its first text is generated in The node is taken when the line's first text is pushed, not at the newline, so a v-if test or a slot's closing bracket maps to its own node. A slot function has the loc of its first child, so it does not count as the node. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
… inMap (#23) * refactor(compiler-sfc): shift template pieces instead of remapping Pieces compiled from the template block are shifted by its offset in the SFC, and codegen takes the caller's source so inline maps check it by identity. Preprocessed templates are left unmapped, since the preprocessor gives no positions. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler-sfc): generate block pieces at their offset in the SFC Codegen takes the offset of the template in the SFC, so the map it renders for a template compiled from the block content is the final one, instead of shifting the pieces and rendering a second map. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler-sfc): place the template in the SFC by its AST, not inMap The AST of the descriptor's template now has the loc of the block, so compileTemplate takes the SFC and the block's start from it, also for a custom compiler that cannot reuse it. Errors are moved by that start, columns on its first line included. inMap is no longer read. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * test(compiler-sfc): place errors of a template whose content repeats earlier in the SFC Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…pieces (#24) * refactor(compiler-sfc): shift template pieces instead of remapping Pieces compiled from the template block are shifted by its offset in the SFC, and codegen takes the caller's source so inline maps check it by identity. Preprocessed templates are left unmapped, since the preprocessor gives no positions. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler-sfc): generate block pieces at their offset in the SFC Codegen takes the offset of the template in the SFC, so the map it renders for a template compiled from the block content is the final one, instead of shifting the pieces and rendering a second map. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * refactor(compiler-sfc): place the template in the SFC by its AST, not inMap The AST of the descriptor's template now has the loc of the block, so compileTemplate takes the SFC and the block's start from it, also for a custom compiler that cannot reuse it. Errors are moved by that start, columns on its first line included. inMap is no longer read. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * test(compiler-sfc): place errors of a template whose content repeats earlier in the SFC Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> * perf(compiler): render no template map for a caller that renders the pieces compileScript inlines the template by its pieces and never read the map that codegen rendered from them. Codegen given pieceSource now leaves the map to its caller, and the preamble of an inlined render function builds no pieces. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
compiler-sfc no longer exports MagicString, which @vue/repl 4.7.2 imports, so the playground preview fails in dev. repl main (59212b9) rewrites modules without it; use its pkg.pr.new build until a release ships it. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
c2af455 to
1fb793e
Compare
The pieces of template codegen dropped the names that the source-map codegen gave, e.g. `foo` for `_ctx.foo`. A located identifier whose generated text differs from it now names its piece, which muggle-string writes to `names`. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…plays it
A text value kept only its expression, so `toDisplayString(` mapped to the
expression in the interpolation instead of its `{{`, and that of a v-text on
a component mapped nowhere. Set-text operations now keep the loc of the text,
interpolation or v-text that displays each value, and a v-text prop that is
displayed keeps the loc of its directive, as in compiler-dom.
Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…internal addPiece, createSourcePiece, createSourceMap and CodegenPiece are exported only for the codegen of compiler-vapor and compiler-sfc, so they and the `pieces` of the codegen contexts are internal and stay out of the d.ts. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
… at the <script setup> tags by rank Each piece of that code is inserted where it is produced, by the writer of its rank, instead of being kept in a variable and joined into one string in its final order: the helper imports, the template preamble and the import of a re-exported default before all of the output, and the setup() head, the async temp variables, the css vars code, the returned bindings and the end of setup() at the tags of <script setup>. The ranks decide their order, so it no longer depends on where the code is joined or on the order of the calls. The output is unchanged. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…waits in it In `await await foo`, both awaits end at one char, and the code after each was placed there in the order of the calls: the outer await, processed first, put its code inside the inner one's. Each await now writes that code by the writer of a rank above those of the awaits in it, so the inner await's code is inside the outer one's whatever the order of the calls. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
… setup() to the module The arguments of defineProps, withDefaults, defineEmits, defineOptions and the prop options of defineModel are hoisted into the component options, so their code runs in the module, not in setup(). The walk for top-level awaits still processed an await in them: it made setup() async and wrote the async context code into their removed range, as `_useModel(__props, 'n'(` or `__props(\n ([__temp,__restore] = _withAsyncContext(() => ))`, or, before this branch, threw for defineEmits. The walk now skips the hoisted arguments, which one list gives to it and to the check of their references to setup() bindings, so an await in them is the module's, as their other code is. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…rapped in a factory A destructured prop default that is not a literal, a function or an external identifier is placed in a factory function of the props, which runs for each instance outside of setup(). An await in it is not in an async function there: the output did not parse (`a: () => (await foo())`), and no factory can give the awaited value, as an async one gives a promise. This is the case an await in a hoisted macro argument is not the module's, so it is now an error naming the prop. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
The props, emits, options and model options copied into the component options were written as strings and mapped nowhere. Generate them as code whose copies of the source are ranges of it, so they map to it. extractRuntimeProps keeps returning a string. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…be split Options that are not an object of static keys were copied into the props of the component and left in the useModel() call, so they were evaluated in the module and again in every setup(), and a reference to a local of <script setup> threw when the module loaded. Hoist them to a module-level declaration that both read, and check them as hoisted macro arguments. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
The render function was inserted as text and, when rendering the map, found again by searching the rendered text for it to splice its pieces in. Insert its pieces instead. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
1.0.3 is deprecated. 1.0.2 is past minimumReleaseAge, so its exemption is removed. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
…f push() The code pushed to a CodegenContext is no longer tracked by position, so push() reads no newlineIndex: newline() appends its unmapped text itself. Both are kept for compatibility, to be removed in a later minor. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
The rule that text without a node maps to the end of the last node on its line, or else to the end of the node it is generated in, lived in core's codegen context and, without the fallback, again in Vapor's codeFragmentToString. It is now one piece writer in compiler-core (createPieceWriter, internal), used by both. Vapor gives the node through a fragment of the code of a compound expression, so the leading text of an expression on a line with nothing mapped before it, e.g. the `!` of `const __ok = !_ctx.ok`, maps to the end of the expression instead of nowhere. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
Every map the compilers give has `version: 3`, but RawSourceMap typed it a string, as source-map-js does, so the maps rendered by muggle-string and the one parse builds were cast through unknown. The type is now a number and the casts are gone. postcss's map, typed by source-map-js, gets the number restated when compileStyle returns it; the tests that hand maps to source-map-js's consumer pass them untyped, as some already did. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
|
/ecosystem-ci run |
Vitest browser mode makes the dependency scan resolve @vue/compiler-core to its CJS entry, so the scan missed the dependencies of the aliased source (entities/decode, muggle-string) and Vite reloaded the test page when it optimized them late, failing the import of the vapor e2e test. Resolve the package to its source in the scan as an interim, and drop the entities/decode excludes it made necessary. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
|
📝 Ran ecosystem CI: Open
|
The test stripped the pieces of a compiler that, given the piece source, also returns no map, so it asserted the template unmapped while giving nothing to map. A third-party compiler maps its input; its map is placed at the template block, as it was before the pieces. Give the test such a compiler and mark it expected-fail until compileTemplate places that map.
…pected-fail The preprocessor gives no positions of its output in the template, so no map of it can be right and none is given. List the map it blocks as an expected-fail test beside the one asserting no wrong map.
…ce-map-js The packages no longer depend on source-map-js; only the tests read maps with it. Read them with trace-mapping, a consumer independent of muggle-string, which renders the maps, and drop source-map-js from the root devDependencies and the catalog. Regenerating the lockfile also resolves the vue that the benchmark's @vitejs/plugin-vue gets as an auto-installed peer to 3.6.0-rc.14.
The explorer was the last part of the repo reading maps with source-map-js. Its highlight spans up to the next mapping on the line, as the column spans of source-map-js did. A cursor between mappings now finds one on its own line only, instead of the last one of an earlier line.
…e-mapping" This reverts commit e84987f.
… of source-map-js" This reverts commit 027c836.
…ource-map-js The packages render source maps with muggle-string and no longer depend on source-map-js; only the tests read maps with it, a second implementation of the format in the repo. Decode the maps with muggle-string's decodeMappings, which needs muggle-string 1.0.3, and drop source-map-js from the root devDependencies and the catalog. Regenerating the lockfile also resolves the vue that the benchmark's @vitejs/plugin-vue gets as an auto-installed peer to 3.6.0-rc.14.
Decode the map with muggle-string's decodeMappings, which the bundle already carries through the compiler, instead of a source-map-js consumer. The template-to-output lookup stays on the line of the cursor rather than falling back to an earlier line.
The code that an await nested in another await's argument generates now sits one level deeper than the outer await's, and its closing parenthesis lines up with the line it opens on. Only whitespace changes; the code and the mapped and unmapped ranges of its source map are the same. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
@vue/compiler-sfcno longer edits scripts with magic-string and no longer re-exportsMagicString(an intentional break, see Downstream);@vue/compiler-core,@vue/compiler-vapor,@vue/compiler-sfcand@vue/compatno longer depend onsource-map-js; code output is unchanged, only source maps change.Why
@vue/compiler-sfcdrops from 12 to 11 packages.source-map-jsstays in that tree only because postcss depends on it.Fixed
`const __returned__`, inserted by `compileScript`
`_ctx.bar` in a multi-line `:class`
vapor `_ctx.selected` in `_createSelector`
`_createTextVNode(` of `a`
`_toDisplayString(` with `inlineTemplate`
`_withDirectives(` of `v-model`
`_toDisplayString(` with a custom `compiler` and `inlineTemplate`
the error of a custom `compiler`
`_ctx.record('enter', el)` in a multi-line `@enter`
`_openBlock(` of a `v-for` row
`_toDisplayString(` in a `v-for` row
_withCtx(of a<template #default>slotvapor `_toDisplayString(` in a v-for row
vapor `_toDisplayString(` of `v-text`
vapor `_toDisplayString(` of `v-text` on a component
await awaitin<script setup>base:
this PR:
awaitgetsundefined42`await` in a macro argument hoisted out of `setup()`
<script setup>const n = defineModel('n', { default: await foo() })SyntaxError: Unexpected token ')'<Suspense>const n = defineModel('n', { get: v => v * 2, default: await foo() })SyntaxError: Unexpected token '('<Suspense>const p = defineProps({ a: { default: await foo() } })<!---->without<Suspense><Suspense>const p = withDefaults(defineProps<{ a?: number }>(), { a: await foo() })<!---->without<Suspense><Suspense>const e = defineEmits(await foo())Cannot split a chunk that has already been edited<Suspense>defineOptions({ name: await foo() })SyntaxError: Unexpected token ')'<Suspense>`await` in a destructured prop default
<script setup>const { a = await foo() } = defineProps(['a'])a: () => (await foo()),SyntaxError: Unexpected reserved word 'await'Default value of prop "a" cannot contain await because it is evaluated in a factory function, outside of setup().const { a = { b: await foo() } } = defineProps<{ a?: object }>()default: () => ({ b: await foo() }),SyntaxError: Unexpected reserved word 'await'Default value of prop "a" cannot contain await because it is evaluated in a factory function, outside of setup().`defineProps()` options hoisted out of `setup()`
`defineModel()` options that can't be split
<script setup>, 2 instancesconst n = defineModel('n', makeOptions())makeOptionsruns 3 timesmakeOptionsruns oncecompileScriptmapsourceswithinlineTemplate, filenameC:\proj\src\App.vue["C:/proj/src/App.vue", "C:\\proj\\src\\App.vue"]["C:\\proj\\src\\App.vue"]compileTemplatewithinMap, in@vue/compiler-sfcbundled by esbuild withkeepNamesReferenceError: __name is not definedResults
Base is the
minormerge-base 747e8d6 and this PR is 2c1842a (branch tip now 045fae5; table still that commit), measured on 1297.vuefiles with Node 24 on Apple Silicon, one round. CPU is user + sys.compileScriptwarm, maps on (3795 calls)compileScriptcold, maps on (6130 calls)compileTemplate,inMap, noast(2574 calls)parse,sourceMap(1297 files)compileTemplatewithastcompileRetained heap of 1297 parsed descriptors: base 113.4 MB, this PR 42.0 MB (-63%).
compiler-sfc.esm-browser.jscompiler-vapor.esm-browser.jsvue.global.prod.jsvite.config.ts: Vitest browser mode's dep scan resolves@vue/compiler-coreto its CJS entry and misses source dependencies (e.g.muggle-string), so Vite optimizes them late and reloads the test page. A scan plugin forces the source alias; the old per-projectentities/decodeoptimizeDeps.excludeentries are removed.Downstream
@vue/replMagicStringis no longer re-exported fromvue/compiler-sfc(or@vue/compiler-sfc). Intentional; import frommagic-stringinstead. 4.7.2 and earlier break; fix is on main, to be released in 4.7.3.MagicStringimport (MagicString is not a constructorat 30:13). AlsobundleSourceMapthrows on generated-only segments: compiler-inserted code has no source, sooriginalLine/originalColumnarenull; copying asoriginal: { line, column }fails at 167:19. Skip or passoriginal: nullwhenm.sourceisnull.@vitejs/plugin-vuevue-sourcemapsnapshots (serve-js,serve-ts,serve-html,serve-no-script,serve-empty-script,serve-no-template) change onlymappings(token maps instead of per-character; generated-only segments on compiler-inserted lines). Update with-u.prop.arg.loc.start.offsettoNumber.POSITIVE_INFINITYso Volar does not duplicate type hints; ranges must be in0..source.length, so compile withsourceMap: truethrowsRangeError. Remove that poison offset upstream; Vue will not special-case it.