Skip to content
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

Add support for sourcemap #5

Merged
merged 3 commits into from
Mar 22, 2017
Merged

Add support for sourcemap #5

merged 3 commits into from
Mar 22, 2017

Conversation

Toilal
Copy link
Contributor

@Toilal Toilal commented Mar 21, 2017

Close #4

Well, I dive deep into sourcemap generation to understand how to implement this, bit it seems to be the right way to support sourcemap generated by any previous loader in the chain.

Tested with TypeScript.

@Toilal
Copy link
Contributor Author

Toilal commented Mar 21, 2017

I'll fix build and make more manual tests tomorrow.

@Toilal
Copy link
Contributor Author

Toilal commented Mar 21, 2017

Build fixed, and works on TypeScript and ES6 using #inline-source-map.

Copy link
Owner

@ktsn ktsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider one more case - when previous source map does not exist even though the user enables source map. (e.g. there are no loader before this loader)

We can use this.sourceMap whether we should output source map.
https://webpack.js.org/api/loaders/#sourcemap

lib/index.js Outdated
module.exports = function(contents) {
const sourceMap = require('source-map')
const SourceMapConsumer = sourceMap.SourceMapConsumer
const SourceMapGenerator = sourceMap.SourceMapGenerator
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this line since it's not used?

lib/index.js Outdated
@@ -39,8 +45,30 @@ module.exports = function(contents) {
}
})

return genCode.generate(res)
+ (hasComponent ? genHotReload(id) : '')
if (hasComponent) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to negate this condition and return in this block early so that we can reduce the nesting level 🙂

@Toilal
Copy link
Contributor Author

Toilal commented Mar 22, 2017

Should be ok now. Thanks for the really good review !

lib/index.js Outdated
const id = genId(this.resourcePath)
let hasComponent = false

const ast = acorn.parse(contents, {
sourceType: 'module'
sourceType: 'module',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think I can remove locations and sourceFile option when this.sourceMap is falsy.

@ktsn
Copy link
Owner

ktsn commented Mar 22, 2017

@Toilal Looks great. Can we fix the lint error? 🙂

@Toilal
Copy link
Contributor Author

Toilal commented Mar 22, 2017

Fixed

@ktsn
Copy link
Owner

ktsn commented Mar 22, 2017

Thanks. Great work! 👍

@ktsn ktsn merged commit b9357ee into ktsn:master Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants