Rework API for sourcemap filenames and paths.

This commit is contained in:
Jason Walton
2013-03-07 21:26:09 -05:00
parent 185b2ce632
commit f85d19b459
10 changed files with 61 additions and 247 deletions

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.1
(function() {
var Lexer, compile, ext, fs, generateV3SourceMapOptions, helpers, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, _ref,
var Lexer, compile, ext, fs, helpers, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, _ref,
__hasProp = {}.hasOwnProperty;
fs = require('fs');
@@ -39,33 +39,8 @@
exports.helpers = helpers;
generateV3SourceMapOptions = function(options) {
var cwd, sourceRoot;
if (options == null) {
options = {};
}
console.log("Generating v3 source map");
cwd = options.workingDirectory;
if (!options.filename) {
return {};
}
if (options.jsPath) {
sourceRoot = helpers.relativePath(options.jsPath, ".", cwd);
return {
sourceRoot: sourceRoot,
sourceFile: helpers.relativePath(".", options.filename, cwd),
generatedFile: helpers.baseFileName(options.jsPath)
};
}
return {
sourceRoot: "",
sourceFile: helpers.baseFileName(options.filename),
generatedFile: helpers.baseFileName(options.filename, true) + ".js"
};
};
exports.compile = compile = function(code, options) {
var answer, currentColumn, currentLine, err, fragment, fragments, header, js, merge, newLines, sourceMap, v3Options, _j, _len1;
var answer, currentColumn, currentLine, err, fragment, fragments, header, js, merge, newLines, sourceMap, _j, _len1;
if (options == null) {
options = {};
}
@@ -112,8 +87,7 @@
};
if (sourceMap) {
answer.sourceMap = sourceMap;
v3Options = generateV3SourceMapOptions(options);
answer.v3SourceMap = sourcemap.generateV3SourceMap(sourceMap, v3Options);
answer.v3SourceMap = sourcemap.generateV3SourceMap(sourceMap, options);
}
return answer;
} else {

View File

@@ -483,15 +483,34 @@
};
compileOptions = function(filename, base) {
return {
var answer, cwd, jsDir, jsPath;
answer = {
filename: filename,
literate: helpers.isLiterate(filename),
bare: opts.bare,
header: opts.compile,
sourceMap: opts.map,
jsPath: filename !== null && base !== null ? outputPath(filename, base) : null,
workingDirectory: process.cwd()
sourceMap: opts.map
};
if (filename) {
if (base) {
cwd = process.cwd();
jsPath = outputPath(filename, base);
jsDir = path.dirname(jsPath);
answer = helpers.merge(answer, {
jsPath: jsPath,
sourceRoot: path.relative(jsDir, cwd),
sourceFiles: [path.relative(cwd, filename)],
generatedFile: helpers.baseFileName(jsPath)
});
} else {
answer = helpers.merge(answer, {
sourceRoot: "",
sourceFiles: [helpers.baseFileName(filename)],
generatedFile: helpers.baseFileName(filename, true) + ".js"
});
}
}
return answer;
};
forkNode = function() {

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.1
(function() {
var buildLocationData, extend, flatten, last, normalizePath, repeat, _ref;
var buildLocationData, extend, flatten, last, repeat, _ref;
exports.starts = function(string, literal, start) {
return literal === string.substr(start, literal.length);
@@ -179,67 +179,4 @@
return /\.(litcoffee|coffee\.md)$/.test(file);
};
exports.normalizePath = normalizePath = function(path, removeTrailingSlash) {
var i, newParts, part, parts, root, _i, _len;
if (removeTrailingSlash == null) {
removeTrailingSlash = false;
}
root = false;
parts = path.split('/');
newParts = [];
i = 0;
if (parts.length > 1 && parts[0] === '') {
parts.shift();
root = true;
}
for (i = _i = 0, _len = parts.length; _i < _len; i = ++_i) {
part = parts[i];
if (part === '.' || part === '') {
if ((i === parts.length - 1) && !removeTrailingSlash) {
newParts.push('');
}
} else if (part === '..') {
if (newParts.length === 0 || (newParts.length && last(newParts === '..'))) {
newParts.push('..');
} else {
newParts.pop();
}
} else {
newParts.push(part);
}
}
if (root) {
if (newParts.length === 0) {
return '/';
}
if (newParts.length[0] === '..') {
throw new Error("Invalid path: " + path);
}
newParts.unshift('');
}
return newParts.join('/');
};
exports.relativePath = function(from, to, cwd) {
var answer;
if (cwd == null) {
cwd = null;
}
if (cwd) {
from = cwd + "/" + from;
to = cwd + "/" + to;
}
from = (normalizePath(from)).split('/');
to = (normalizePath(to)).split('/');
while (from.length > 0 && to.length > 0 && from[0] === to[0]) {
from.shift();
to.shift();
}
if (from.length && from[0] === "..") {
throw new Error("'cwd' must be specified if 'from' references parent directory: " + (from.join('/')) + " -> " + (to.join('/')));
}
answer = repeat("../", from.length - 1);
return answer + ("" + (to.join('/')));
};
}).call(this);

View File

@@ -114,13 +114,13 @@
})();
exports.generateV3SourceMap = function(sourceMap, options) {
var answer, generatedFile, lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, sourceFile, sourceRoot, writingGeneratedLine;
var answer, generatedFile, lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, sourceFiles, sourceRoot, writingGeneratedLine;
if (options == null) {
options = {};
}
sourceRoot = options.sourceRoot || "";
sourceFile = options.sourceFile || null;
generatedFile = options.generatedFile || null;
sourceFiles = options.sourceFiles || [""];
generatedFile = options.generatedFile || "";
writingGeneratedLine = 0;
lastGeneratedColumnWritten = 0;
lastSourceLineWritten = 0;
@@ -151,7 +151,7 @@
version: 3,
file: generatedFile,
sourceRoot: sourceRoot,
sources: sourceFile ? [sourceFile] : [],
sources: sourceFiles,
names: [],
mappings: mappings
};