-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/preprocessor sourcemaps #5428
Conversation
sort devDependencies rename to compile_options.sourcemap file src/compiler/utils/string_with_map.ts * indent with tabs * run prettier * remove extra whitespace * add newline at end of file * wrap long lines * rephrase some comments
move string_with_map.ts to string_with_sourcemap.ts rename GeneratedStringWithMap to StringWithSourcemap rename offset_source_location to sourcemap_add_offset rename source_maps to sourcemap_list rename source_locator to get_location rename as_sourcemap to get_sourcemap rename encode to sourcemap_encode move { brace to line before add some comments
rename decode to sourcemap_decode allow self-closing <style/>
move fn replace_async back to old place to reduce line diffs fn preprocess: allow empty argument `preprocessor` (noop) make fns replace_async, get_replacement pure fns pass filename, get_location as argument restore old format to reduce line diffs remove empty fields of sourcemap: file, sourcesContent
use _config.js, indent with tabs, rename variables,
It's not super obvious to me how you'd split this PR up into multiple, but if that's something that's possible I think it would help it get in faster. It is a bit intimidating to review such a large change. There are a couple files where the only edit was to add a new line to the end of the file and I think those files could be dropped from the PR |
blame my strategy of "release soon and release often" i expect the 13+ commits would be squashed into one commit, no? some edits were revoked in the process the original patch was 960 lines of diff
naah, those are easy to review. git diff complains when files dont end with newline |
Ignore my comments about the quotes for now. I have removed those comments. It seems the current codebase is quite inconsistent. We should set an eslint rule for that (sveltejs/eslint-config#5). Unfortunately eslint for tabs vs spaces is harder because the typescript eslint spacing rules are broken |
concerning the sourcemap.sources issuethe sourcemap-combiner function in in my naive understanding so the .. thats my todo for tomorrow, other than that im happy with the code edit: done by not doing. instead, optimize fn concat: concerning the eslint warnings in test/sourcemaps/samples/sourcemap-sources/_config.jsedit: this is a bug in Lines 7 to 13 in 46a83a5
i wonder why this import-to-require transpile is not done with babel, like // .mocharc.js
module.exports = {
require: ['@babel/register']
}; // .babelrc[.json]
{
"presets": ["@babel/preset-env"]
} //import MagicString, { Bundle } from 'magic-string';
// TODO why does this break mocha?
// SyntaxError: Cannot use import statement outside a module
import MagicString from 'magic-string';
const bundle = new MagicString.Bundle();
// eslint warning: import/no-named-as-default-member
// `MagicString` also has a named export `Bundle`.
// Check if you meant to write `import {Bundle} from 'magic-string'` instead
bundle.addSource({
filename: "foo",
content: new MagicString("bar")
}); so i need both still havent found out how mocha can even use ES6 files getting rid off that warning would be nice currently 1615 lines of diff vs svelte/master .... happy reviewing : / |
3fe1fcc
to
422cc0d
Compare
a commit a day, keeps the merge day away
i can only repeat what halfnelson said in #5015
|
@milahu we just updated our eslint config to standardize on single quotes. Would you be able to rebase this PR against master and then make sure the new lint setup passes against this PR? |
4a1c87a
to
18003d6
Compare
So I got around to reviewing this awesome work by @milahu . The PR as it is large, and might be best refactored into 4 smaller ones, that build on each other.
I have had a go at 1 & 2 to get this functionality on line.
I think the only ninja edit was a rename of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment about splitting the code.
We should probably keep the string | object
in the Processed definition. This will avoid having to install remapper as a dependency for users of our types.
Maybe we should just define a compatible Interface def as part of svelte?
There aren't heaps of unit tests in the code (I really should have added them as part of my initial PR) but StringWithSourcemap
and merge_tables
and sourcemap_add_offset
probably need some at some stage.
Thanks for the great work @milahu , for picking this up and running it so far, and finding the bugs :)
The test refactor in #5583 has been checked in so this PR could probably be rebased to be a bit smaller now |
progress : ] quick note: there are two more commits hidden in |
Thanks, it looks like I missed those two, I'll ensure they are included.
|
Second PR here #5584 which includes the actual source map support (without the encode/decode optimisation) |
continue request #5015 by @halfnelson
this patch got larger than expected. let me know if i
shouldmust make it smallermost noise is in refactoring of tests
done - major changes
res.get_sourcemap()
andremapping(sourcemap_list)
- make preprocess 20% faster in benchmarksvelte.preprocess
andsvelte.compile
- waiting for add print option sourceMapEncodeMappings Rich-Harris/code-red#51 and add option decodeMappings to remapping ampproject/remapping#88done - small changes
replace_async
andget_replacement
to global scope, make pure fn, avoid using global varspreprocessors.filename
is ignored ifoptions.filename
is setnames
field, verify merging and remapping of map.namesnames is an array of original symbol names that were changed in the transform (sample: terser.minify)
much faster than immutablearray1.push(...array2)
which is limited by max call stack size of ~100Ktest/setup.js
- support default + named importdecode_mappings
.svelte.compile
prefers to consume decoded mappings - transcoding of mappings is expensivecss.map.version = 3
in svelte.compile. solved by workaround. magic-string type DecodedSourceMap should have propertyversion
removed
todo
compile/Component.ts
string_with_sourcemap.ts
todo - document
ThisComponent.svelte
. limitation: included files must be 'original source files' = leaf nodes = can not have sourcemapsbugfix in fn merge_tables
map.sources[1]
was returningundefined
this was a bug in fn merge_tables, fixed in b7d5974
also
extended
can be undefined, so we need an extra check