mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
merge
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
(function() {
|
||||
var Lexer, compile, ext, fs, helpers, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, _ref,
|
||||
var Lexer, compile, ext, fs, generateV3SourceMapOptions, helpers, lexer, loadFile, parser, path, sourcemap, vm, _i, _len, _ref,
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
fs = require('fs');
|
||||
@@ -39,16 +39,39 @@
|
||||
|
||||
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, coffeeFile, currentColumn, currentLine, err, fragment, fragments, header, js, jsFile, merge, newLines, sourceMap, _j, _len1;
|
||||
var answer, currentColumn, currentLine, err, fragment, fragments, header, js, merge, newLines, sourceMap, v3Options, _j, _len1;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
merge = exports.helpers.merge;
|
||||
try {
|
||||
if (options.sourceMap) {
|
||||
coffeeFile = helpers.baseFileName(options.filename);
|
||||
jsFile = helpers.baseFileName(options.filename, true) + ".js";
|
||||
sourceMap = new sourcemap.SourceMap();
|
||||
}
|
||||
fragments = (parser.parse(lexer.tokenize(code, options))).compileToFragments(options);
|
||||
@@ -89,7 +112,8 @@
|
||||
};
|
||||
if (sourceMap) {
|
||||
answer.sourceMap = sourceMap;
|
||||
answer.v3SourceMap = sourcemap.generateV3SourceMap(sourceMap, coffeeFile, jsFile);
|
||||
v3Options = generateV3SourceMapOptions(options);
|
||||
answer.v3SourceMap = sourcemap.generateV3SourceMap(sourceMap, v3Options);
|
||||
}
|
||||
return answer;
|
||||
} else {
|
||||
|
||||
@@ -149,8 +149,11 @@
|
||||
|
||||
compileScript = function(file, input, base) {
|
||||
var compiled, err, o, options, t, task;
|
||||
if (base == null) {
|
||||
base = null;
|
||||
}
|
||||
o = opts;
|
||||
options = compileOptions(file);
|
||||
options = compileOptions(file, base);
|
||||
try {
|
||||
t = task = {
|
||||
file: file,
|
||||
@@ -181,7 +184,7 @@
|
||||
if (o.print) {
|
||||
return printLine(t.output.trim());
|
||||
} else if (o.compile || o.map) {
|
||||
return writeJs(base, t.file, t.output, t.sourceMap);
|
||||
return writeJs(base, t.file, t.output, options.jsPath, t.sourceMap);
|
||||
} else if (o.lint) {
|
||||
return lint(t.file, t.output);
|
||||
}
|
||||
@@ -388,12 +391,11 @@
|
||||
return path.join(dir, basename + extension);
|
||||
};
|
||||
|
||||
writeJs = function(base, sourcePath, js, generatedSourceMap) {
|
||||
var compile, jsDir, jsPath, sourceMapPath;
|
||||
writeJs = function(base, sourcePath, js, jsPath, generatedSourceMap) {
|
||||
var compile, jsDir, sourceMapPath;
|
||||
if (generatedSourceMap == null) {
|
||||
generatedSourceMap = null;
|
||||
}
|
||||
jsPath = outputPath(sourcePath, base);
|
||||
sourceMapPath = outputPath(sourcePath, base, ".map");
|
||||
jsDir = path.dirname(jsPath);
|
||||
compile = function() {
|
||||
@@ -480,13 +482,15 @@
|
||||
}
|
||||
};
|
||||
|
||||
compileOptions = function(filename) {
|
||||
compileOptions = function(filename, base) {
|
||||
return {
|
||||
filename: filename,
|
||||
literate: helpers.isLiterate(filename),
|
||||
bare: opts.bare,
|
||||
header: opts.compile,
|
||||
sourceMap: opts.map
|
||||
sourceMap: opts.map,
|
||||
jsPath: filename !== null && base !== null ? outputPath(filename, base) : null,
|
||||
workingDirectory: process.cwd()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.6.1
|
||||
(function() {
|
||||
var buildLocationData, extend, flatten, _ref;
|
||||
var buildLocationData, extend, flatten, last, normalizePath, repeat, _ref;
|
||||
|
||||
exports.starts = function(string, literal, start) {
|
||||
return literal === string.substr(start, literal.length);
|
||||
@@ -12,6 +12,19 @@
|
||||
return literal === string.substr(string.length - len - (back || 0), len);
|
||||
};
|
||||
|
||||
exports.repeat = repeat = function(str, n) {
|
||||
var res;
|
||||
res = '';
|
||||
while (n > 0) {
|
||||
if (n & 1) {
|
||||
res += str;
|
||||
}
|
||||
n >>>= 1;
|
||||
str += str;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
exports.compact = function(array) {
|
||||
var item, _i, _len, _results;
|
||||
_results = [];
|
||||
@@ -70,7 +83,7 @@
|
||||
return val;
|
||||
};
|
||||
|
||||
exports.last = function(array, back) {
|
||||
exports.last = last = function(array, back) {
|
||||
return array[array.length - (back || 0) - 1];
|
||||
};
|
||||
|
||||
@@ -166,4 +179,67 @@
|
||||
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);
|
||||
|
||||
@@ -113,14 +113,14 @@
|
||||
|
||||
})();
|
||||
|
||||
exports.generateV3SourceMap = function(sourceMap, sourceFile, generatedFile) {
|
||||
var answer, lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, writingGeneratedLine;
|
||||
if (sourceFile == null) {
|
||||
sourceFile = null;
|
||||
}
|
||||
if (generatedFile == null) {
|
||||
generatedFile = null;
|
||||
exports.generateV3SourceMap = function(sourceMap, options) {
|
||||
var answer, generatedFile, lastGeneratedColumnWritten, lastSourceColumnWritten, lastSourceLineWritten, mappings, needComma, sourceFile, sourceRoot, writingGeneratedLine;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
sourceRoot = options.sourceRoot || "";
|
||||
sourceFile = options.sourceFile || null;
|
||||
generatedFile = options.generatedFile || null;
|
||||
writingGeneratedLine = 0;
|
||||
lastGeneratedColumnWritten = 0;
|
||||
lastSourceLineWritten = 0;
|
||||
@@ -150,7 +150,7 @@
|
||||
answer = {
|
||||
version: 3,
|
||||
file: generatedFile,
|
||||
sourceRoot: "",
|
||||
sourceRoot: sourceRoot,
|
||||
sources: sourceFile ? [sourceFile] : [],
|
||||
names: [],
|
||||
mappings: mappings
|
||||
|
||||
Reference in New Issue
Block a user