Skip to content

Commit 625cf55

Browse files
committed
feat(espowerify): use espower-source directly since espower-source 0.9.0 is backported from espowerify
1 parent 77d6ce1 commit 625cf55

File tree

2 files changed

+4
-76
lines changed

2 files changed

+4
-76
lines changed

Diff for: index.js

+2-68
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,7 @@
1010
'use strict';
1111

1212
var through = require('through'),
13-
espower = require('espower'),
14-
esprima = require('esprima'),
15-
escodegen = require('escodegen'),
16-
extend = require('xtend'),
17-
convert = require('convert-source-map'),
18-
transfer = require('multi-stage-sourcemap').transfer;
19-
20-
function mergeSourceMap(incomingSourceMap, outgoingSourceMap) {
21-
if (typeof outgoingSourceMap === 'string' || outgoingSourceMap instanceof String) {
22-
outgoingSourceMap = JSON.parse(outgoingSourceMap);
23-
}
24-
if (!incomingSourceMap) {
25-
return outgoingSourceMap;
26-
}
27-
return JSON.parse(transfer({fromSourceMap: outgoingSourceMap, toSourceMap: incomingSourceMap}));
28-
}
29-
30-
function handleUpstreamSourceMap (jsCode, options) {
31-
var inMap;
32-
if (options.sourceMap) {
33-
inMap = options.sourceMap;
34-
} else {
35-
var commented = convert.fromSource(jsCode);
36-
if (commented) {
37-
inMap = commented.toObject();
38-
options.sourceMap = inMap;
39-
}
40-
}
41-
return inMap;
42-
}
43-
44-
function instrument (jsCode, filepath, options) {
45-
var jsAst = esprima.parse(jsCode, {tolerant: true, loc: true, source: filepath});
46-
var modifiedAst = espower(jsAst, options);
47-
// keep paths absolute by not using `file` and `sourceMapRoot`
48-
// paths will be resolved by mold-source-map
49-
return escodegen.generate(modifiedAst, {
50-
sourceMap: true,
51-
sourceMapWithCode: true
52-
});
53-
}
54-
55-
function mergeEspowerOptions (options, filepath) {
56-
return extend(espower.defaultOptions(), options, {
57-
destructive: true,
58-
path: filepath
59-
});
60-
}
61-
62-
function transform (jsCode, filepath, options) {
63-
var espowerOptions = mergeEspowerOptions(options, filepath);
64-
var inMap = handleUpstreamSourceMap(jsCode, espowerOptions);
65-
var instrumented = instrument(jsCode, filepath, espowerOptions);
66-
var outMap = convert.fromJSON(instrumented.map.toString());
67-
if (inMap) {
68-
var mergedRawMap = mergeSourceMap(inMap, outMap.toObject());
69-
var reMap = convert.fromObject(mergedRawMap);
70-
reMap.setProperty('sources', inMap.sources);
71-
reMap.setProperty('sourcesContent', inMap.sourcesContent);
72-
return instrumented.code + '\n' + reMap.toComment() + '\n';
73-
} else {
74-
// Keeping paths absolute. Paths will be resolved by mold-source-map.
75-
outMap.setProperty('sources', [filepath]);
76-
outMap.setProperty('sourcesContent', [jsCode]);
77-
return instrumented.code + '\n' + outMap.toComment() + '\n';
78-
}
79-
}
13+
espowerSource = require('espower-source');
8014

8115
/**
8216
* Apply espower through the browserify transform chain.
@@ -95,7 +29,7 @@ function espowerify(filepath, options) {
9529
}
9630

9731
function end() {
98-
stream.queue(transform(data, filepath, options));
32+
stream.queue(espowerSource(data, filepath, options));
9933
stream.queue(null);
10034
}
10135

Diff for: package.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,8 @@
4242
"test": "jshint index.js && mocha"
4343
},
4444
"dependencies": {
45-
"convert-source-map": "~0.4.1",
46-
"escodegen": "~1.3.3",
47-
"espower": "~0.9.0",
48-
"esprima": "~1.2.2",
49-
"multi-stage-sourcemap": "~0.1.1",
50-
"source-map": "~0.1.38",
51-
"through": "~2.3.4",
52-
"xtend": "~4.0.0"
45+
"espower-source": "~0.9.0",
46+
"through": "~2.3.4"
5347
},
5448
"devDependencies": {
5549
"jshint": "~2.5.2",

0 commit comments

Comments
 (0)