Skip to content

Commit 65a8f46

Browse files
Add source maps (#150)
This patch switches to transform-ast, which has an almost identical API to falafel but also generates source maps. transform-ast has a `.walk()` method that we can use to avoid having to parse the source twice just to walk it twice, so this should speed things up a bit too!
1 parent 3c5ed0f commit 65a8f46

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"css-modules"
2222
],
2323
"dependencies": {
24-
"falafel": "^2.1.0",
24+
"acorn-node": "^1.3.0",
2525
"fast-json-parse": "^1.0.2",
2626
"findup": "^0.1.5",
2727
"insert-css": "^2.0.0",
@@ -33,6 +33,7 @@
3333
"static-eval": "^1.1.0",
3434
"style-resolve": "^1.1.0",
3535
"through2": "^2.0.0",
36+
"transform-ast": "^2.4.0",
3637
"xtend": "^4.0.1"
3738
},
3839
"devDependencies": {

transform.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const cssResolve = require('style-resolve').sync
2+
const transformAst = require('transform-ast')
23
const staticEval = require('static-eval')
34
const parse = require('fast-json-parse')
45
const mapLimit = require('map-limit')
56
const through = require('through2')
6-
const falafel = require('falafel')
77
const findup = require('findup')
88
const xtend = require('xtend')
99
const path = require('path')
@@ -77,8 +77,11 @@ function transform (filename, options) {
7777
opts.transform = transforms.concat(opts.transform || []).concat(opts.t || [])
7878

7979
try {
80-
const tmpAst = falafel(src, { ecmaVersion: 8 }, identifyModuleName)
81-
ast = falafel(tmpAst.toString(), { ecmaVersion: 8 }, extractNodes)
80+
ast = transformAst(src, {
81+
parser: require('acorn-node'),
82+
inputFilename: path.basename(filename)
83+
}, identifyModuleName)
84+
ast.walk(extractNodes)
8285
} catch (err) {
8386
return self.emit('error', err)
8487
}
@@ -87,7 +90,9 @@ function transform (filename, options) {
8790
// close stream when done
8891
mapLimit(nodes, Infinity, iterate, function (err) {
8992
if (err) return self.emit('error', err)
90-
self.push(ast.toString())
93+
self.push(ast.toString({
94+
map: opts && opts._flags && opts._flags.debug
95+
}))
9196
self.push(null)
9297
})
9398
})

0 commit comments

Comments
 (0)