-
Notifications
You must be signed in to change notification settings - Fork 2k
[CS2] Fix v3 source map #4671
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
[CS2] Fix v3 source map #4671
Conversation
…t `filename` is, use `filename`; output null instead of an empty string for `sources` or `sourceRoot`
… empty strings; check generated sources array
lydell
left a comment
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.
This all sounds very sensible, but I can't know for sure what's correct. IMO, feel free to merge if you feel confident.
|
I don't feel confident. I thought you were a contributor to |
|
Yep, but there's been a while since I did anything in source-map. And what I learned when contributing there is that it is really difficult to get the edge cases right, because those things aren't really specified so it's mostly about getting the source maps to work with other tools and browers... The more I think about this though, I think we could merge it. Worst case scenario we just revert it if something comes up? |
|
Hmm, but as far as I remember, every source mapping always points to an index in the |
|
I think I'll revert the change to empty strings. I don't want to mess up downstream tools. What about |
|
The Regarding the |
|
I meant that we're only discussing the behavior when someone calls If they didn’t provide one, though, then is it better for |
|
Here’s an example of one downstream tool interacting with these fields: https://github.com/meteor/meteor/blob/devel/packages/non-core/coffeescript-compiler/coffeescript-compiler.js#L29 This PR wouldn’t break that one, at least. I don’t know what downstream tools would break, unless any are checking for empty strings. |
I don't remember the API exactly. What is this supplied filename?
|
|
If we’re going to return See http://coffeescript.org/v2/#nodejs-usage. On the |
Ah, there it is. Isn't that already used for the |
|
The |
|
Sigh. Source maps are always so confusing. |
|
I’m leaning closer and closer to “no one is complaining that this is broken.” |
|
You mean that you'd rather close this and #3075? I guess that's fine, too. |
|
I just don’t know. I feel like if we’re going to change/fix this, we should just do it, especially now before 2.0.0. But on the other hand there aren’t any open issues about this, so if we change this and any downstream tools were relying on this (broken) behavior, we could break them. Then again, breaking them as part of a 2.0.0 release would be the time to do so. I think likely any downstream tools were just working around these missing fields (as Coffeeify did) or using the undocumented You’ve worked with source maps much more than I have. What do you think we should do? |
|
How about we do what TypeScript does? (Based on this.) ts = require 'typescript'
source = "let x: string = 'string'"
result = ts.transpileModule source,
compilerOptions:
module: ts.ModuleKind.CommonJS
sourceMap: yes
console.log JSON.parse result.sourceMapText
{ version: 3,
file: 'module.js',
sourceRoot: '',
sources: [ 'module.ts' ],
names: [],
mappings: 'AAAA,IAAI,CAAC,GAAY,QAAQ,CAAA' }So:
I’m fine with |
…utput empty strings instead of made-up filenames
|
I like the idea of copying the approach of another big project.
I'd rather default to an empty string. (Note this is supposed to be the name of the generated JS file. I'm not sure if any tools actually even use this field.)
👍
I think it's fine to default to
👍 |
Per discussion in #3075, in the
v3SourceMapobject:nullinstead of empty strings, or an empty array instead of[''].options.sourceFiles(an undocumented Node API option) is unspecified, butoptions.filenameis, generate thev3SourceMapsourcesfield from[options.filename]. The API by definition is always only compiling one file.I don’t know if it’s worth documenting the source map
generatedFile(maps tov3SourceMapfile) orsourceFiles(maps tosources) orsourceRoot(maps to same) fields? They seem pretty obscure.