Not generating source maps for some source transformations
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 363
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
I'm writing a source transformation with Recast and when I attempt to replace a node like so:
``` js
const recast = require('recast')
let ast = recast.parse('1 + 1', {sourceFileName: 'source.js'})
ast.program.body[0] = recast.types.builders.expressionStatement(recast.types.builders.literal(2))
console.log(recast.print(ast, {sourceMapName: 'output.map.js'}))
ast = recast.parse('1 + 1', {sourceFileName: 'source.js'})
ast.program.body[0].expression = recast.types.builders.literal(2)
console.log(recast.print(ast, {sourceMapName: 'output.map.js'}))
ast = recast.parse('1 + 1', {sourceFileName: 'source.js'})
ast.program.body[0].expression.type = 'Literal'
ast.program.body[0].expression.value = 2
console.log(recast.print(ast, {sourceMapName: 'output.map.js'}))
```
The result is in all cases the `code` field of the result object being `'2'` like we would expect but the `map` field contains:
```
{ version: 3,
sources: [],
names: [],
mappings: '',
file: 'output.map.js' }
```
...resulting in the browser failing to display the original sources. I haven't found way to write this code that generates a source map. Is there something I'm doing wrong, or if this is a bug, is there a workaround?
(Node 5.11.1, Recast 0.11.8, Mac OS X)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the three recast.parse and recast.print examples from the issue with source maps enabled, comparing the replacement styles and their returned map objects. Trace the source-map generation path for these transformations; done means the transformed code still produces a map containing the original source information instead of empty sources and mappings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100