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

#1 #7

Merged
merged 44 commits into from
Mar 14, 2017
Merged

#1 #7

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1643991
#1 remove sync methods
robvenn Nov 19, 2016
ee1ec12
Replace readFileSync with readFile async to load map file
robvenn Nov 20, 2016
b35e05f
Merge branch 'master' of https://github.com/robinvenneman/vinyl-sourc…
robvenn Nov 21, 2016
1373a17
Remove readFileSync (wip)
robvenn Nov 22, 2016
7f2d0c2
Fix test for add method with failed reading file setting sourceConten…
robvenn Nov 22, 2016
f504c6c
#1 replace remaining readFileSync with async readFile in write method
robvenn Nov 24, 2016
8a29586
Update repository field
robvenn Jan 7, 2017
def74f7
Add async library & refactor add() maps loading
robvenn Jan 7, 2017
42c3933
Refactor add (loadSourceMap) with async
robvenn Jan 7, 2017
73eb6e0
Refactored write() method with async
robvenn Jan 7, 2017
510f6cb
Extract & cleanup registerTokens
robvenn Jan 8, 2017
a487f7d
Refactor registerTokens as iterator with IIFE
robvenn Jan 8, 2017
645b4aa
Remove unneeded else statement
robvenn Jan 8, 2017
1587dd4
use async.each to loadSourcesAsync
phated Feb 9, 2017
5694d35
move try/catch JSON.parse into own named method
phated Feb 9, 2017
206a247
de-nest functions 1 level and use a single waterfall with early exits
phated Feb 9, 2017
e1f0156
the logic in loadMaps was not async so reduce it to procedural code
phated Feb 9, 2017
8f1f5a7
re-order function definition to attempt better diff
phated Feb 9, 2017
dd00956
split generators and helpers into own files
phated Feb 25, 2017
521f747
take stuff out to make tests pass
phated Feb 25, 2017
363c3a6
Rewrote test runner in addjs to mocha, having problems with two tests…
Feb 26, 2017
06f4e6a
refactor loading existing source map (#10)
Feb 26, 2017
6a895e6
Rewrote all tests from tapejs to mochajs
Feb 26, 2017
91f403b
Removing unused map function, deleted unused scripts, and updated err…
Feb 26, 2017
98ac5b0
Fixed broken test case
Feb 26, 2017
ed86cd8
keep on swimming
phated Mar 2, 2017
ff32abe
Pin convert-source-map because they broke stuff in 1.4.0 - need to re…
phated Mar 2, 2017
2deb417
SWITCH
phated Mar 2, 2017
8391306
use file.extname because we already use 1.x of vinyl
phated Mar 2, 2017
3666977
rename some variables
phated Mar 6, 2017
3ed9dcd
working linting
phated Mar 6, 2017
672578c
rename done to onRead
phated Mar 7, 2017
44df158
add TODO to parse
phated Mar 7, 2017
de3211f
named functions
phated Mar 7, 2017
774e0c1
some notes and eachOf changes like in add
phated Mar 7, 2017
63121cc
use file.extname
phated Mar 7, 2017
9957da5
simplify waterfall tasks
phated Mar 7, 2017
6f78e00
move write logic into helpers file
phated Mar 7, 2017
83c2ea2
some simple helper refactor and TODOs
phated Mar 8, 2017
4be4d97
remove function options and comment tests - these will be resolved a …
phated Mar 8, 2017
9262a08
remove function support for sourceRoot option
phated Mar 10, 2017
5f9ef70
Merge remote-tracking branch 'rickyplouis/#1' into #1
phated Mar 14, 2017
f628745
cleanup & linting
phated Mar 14, 2017
a76cb4c
pass error to done
phated Mar 14, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
492 changes: 83 additions & 409 deletions index.js

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions lib/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict';

var css = require('css');
var acorn = require('acorn');
var SourceMapGenerator = require('source-map').SourceMapGenerator;

function generateJs(sourcePath, fileContent) {
var generator = new SourceMapGenerator({ file: sourcePath });
var tokenizer = acorn.tokenizer(fileContent, { locations: true });

while (true) {
var token = tokenizer.getToken();

if (token.type.label === 'eof') {
break;
}
var mapping = {
original: token.loc.start,
generated: token.loc.start,
source: sourcePath
};
if (token.type.label === 'name') {
mapping.name = token.value;
}
generator.addMapping(mapping);
}
generator.setSourceContent(sourcePath, fileContent);

return generator.toJSON();
}

function generateCss(sourcePath, fileContent) {
var generator = new SourceMapGenerator({ file: sourcePath });
var ast = css.parse(fileContent, { silent: true });

function registerTokens(ast) {
if (ast.position) {
generator.addMapping({
original: ast.position.start,
generated: ast.position.start,
source: sourcePath
});
}

for (var key in ast) {
if (key === 'position' || !ast[key]) {
break;
}
if (Object.prototype.toString.call(ast[key]) === '[object Object]') {
registerTokens(ast[key]);
} else if (Array.isArray(ast[key])) {
ast[key].forEach(registerTokens);
}
}
}
registerTokens(ast);
generator.setSourceContent(sourcePath, fileContent);

return generator.toJSON();
}

module.exports = {
js: generateJs,
css: generateCss,
};
Loading