mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Merge branch 'master' of github.com:jashkenas/coffeescript into 2-docs
# Conflicts: # Cakefile # lib/coffee-script/coffee-script.js # src/coffee-script.coffee
This commit is contained in:
commit
2a862d533f
6 changed files with 19 additions and 192 deletions
10
Cakefile
10
Cakefile
|
@ -90,7 +90,11 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
|
|||
|
||||
|
||||
task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
|
||||
code = ''
|
||||
code = """
|
||||
require['../../package.json'] = (function() {
|
||||
return #{fs.readFileSync "./package.json"};
|
||||
})();
|
||||
"""
|
||||
for {name, src} in [{name: 'marked', src: 'lib/marked.js'}]
|
||||
code += """
|
||||
require['#{name}'] = (function() {
|
||||
|
@ -123,14 +127,14 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
|
|||
}(this));
|
||||
"""
|
||||
unless process.env.MINIFY is 'false'
|
||||
{compiledCode} = require('google-closure-compiler-js').compile
|
||||
{compiledCode: code} = require('google-closure-compiler-js').compile
|
||||
jsCode: [
|
||||
src: code
|
||||
languageOut: if majorVersion is 1 then 'ES5' else 'ES6'
|
||||
]
|
||||
outputFolder = "docs/v#{majorVersion}/browser-compiler"
|
||||
fs.mkdirSync outputFolder unless fs.existsSync outputFolder
|
||||
fs.writeFileSync "#{outputFolder}/coffee-script.js", header + '\n' + compiledCode
|
||||
fs.writeFileSync "#{outputFolder}/coffee-script.js", header + '\n' + code
|
||||
console.log "built ... running browser tests:"
|
||||
invoke 'test:browser'
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Generated by CoffeeScript 2.0.0-alpha
|
||||
(function() {
|
||||
var Lexer, SourceMap, base64encode, compile, ext, fn1, formatSourcePosition, fs, getSourceMap, helpers, i, len, lexer, parser, path, ref, sourceMaps, vm, withPrettyErrors,
|
||||
var Lexer, SourceMap, base64encode, compile, ext, fn1, fs, helpers, i, len, lexer, packageJson, parser, path, ref, vm, withPrettyErrors,
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
fs = require('fs');
|
||||
|
@ -17,7 +17,9 @@
|
|||
|
||||
SourceMap = require('./sourcemap');
|
||||
|
||||
exports.VERSION = '2.0.0-alpha';
|
||||
packageJson = require('../../package.json');
|
||||
|
||||
exports.VERSION = packageJson.version;
|
||||
|
||||
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
|
||||
|
||||
|
@ -304,99 +306,4 @@
|
|||
return helpers.throwSyntaxError(`unexpected ${errorText}`, errorLoc);
|
||||
};
|
||||
|
||||
formatSourcePosition = function(frame, getSourceMapping) {
|
||||
var as, column, fileLocation, fileName, functionName, isConstructor, isMethodCall, line, methodName, source, tp, typeName;
|
||||
fileName = void 0;
|
||||
fileLocation = '';
|
||||
if (frame.isNative()) {
|
||||
fileLocation = "native";
|
||||
} else {
|
||||
if (frame.isEval()) {
|
||||
fileName = frame.getScriptNameOrSourceURL();
|
||||
if (!fileName) {
|
||||
fileLocation = `${frame.getEvalOrigin()}, `;
|
||||
}
|
||||
} else {
|
||||
fileName = frame.getFileName();
|
||||
}
|
||||
fileName || (fileName = "<anonymous>");
|
||||
line = frame.getLineNumber();
|
||||
column = frame.getColumnNumber();
|
||||
source = getSourceMapping(fileName, line, column);
|
||||
fileLocation = source ? `${fileName}:${source[0]}:${source[1]}` : `${fileName}:${line}:${column}`;
|
||||
}
|
||||
functionName = frame.getFunctionName();
|
||||
isConstructor = frame.isConstructor();
|
||||
isMethodCall = !(frame.isToplevel() || isConstructor);
|
||||
if (isMethodCall) {
|
||||
methodName = frame.getMethodName();
|
||||
typeName = frame.getTypeName();
|
||||
if (functionName) {
|
||||
tp = as = '';
|
||||
if (typeName && functionName.indexOf(typeName)) {
|
||||
tp = `${typeName}.`;
|
||||
}
|
||||
if (methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1) {
|
||||
as = ` [as ${methodName}]`;
|
||||
}
|
||||
return `${tp}${functionName}${as} (${fileLocation})`;
|
||||
} else {
|
||||
return `${typeName}.${methodName || '<anonymous>'} (${fileLocation})`;
|
||||
}
|
||||
} else if (isConstructor) {
|
||||
return `new ${functionName || '<anonymous>'} (${fileLocation})`;
|
||||
} else if (functionName) {
|
||||
return `${functionName} (${fileLocation})`;
|
||||
} else {
|
||||
return fileLocation;
|
||||
}
|
||||
};
|
||||
|
||||
sourceMaps = {};
|
||||
|
||||
getSourceMap = function(filename) {
|
||||
var answer, j, len1, ref1;
|
||||
if (sourceMaps[filename]) {
|
||||
return sourceMaps[filename];
|
||||
}
|
||||
ref1 = exports.FILE_EXTENSIONS;
|
||||
for (j = 0, len1 = ref1.length; j < len1; j++) {
|
||||
ext = ref1[j];
|
||||
if (helpers.ends(filename, ext)) {
|
||||
answer = exports._compileFile(filename, true);
|
||||
return sourceMaps[filename] = answer.sourceMap;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Error.prepareStackTrace = function(err, stack) {
|
||||
var frame, frames, getSourceMapping;
|
||||
getSourceMapping = function(filename, line, column) {
|
||||
var answer, sourceMap;
|
||||
sourceMap = getSourceMap(filename);
|
||||
if (sourceMap) {
|
||||
answer = sourceMap.sourceLocation([line - 1, column - 1]);
|
||||
}
|
||||
if (answer) {
|
||||
return [answer[0] + 1, answer[1] + 1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
frames = (function() {
|
||||
var j, len1, results;
|
||||
results = [];
|
||||
for (j = 0, len1 = stack.length; j < len1; j++) {
|
||||
frame = stack[j];
|
||||
if (frame.getFunction() === exports.run) {
|
||||
break;
|
||||
}
|
||||
results.push(` at ${formatSourcePosition(frame, getSourceMapping)}`);
|
||||
}
|
||||
return results;
|
||||
})();
|
||||
return `${err.toString()}\n${frames.join('\n')}\n`;
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
var Assign, Block, Literal, Value, ast, err, js, ref1, referencedVars, token, tokens;
|
||||
input = input.replace(/\uFF00/g, '\n');
|
||||
input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
|
||||
input = input.replace(/^\s*try\s*{([\s\S]*)}\s*catch.*$/m, '$1');
|
||||
ref1 = require('./nodes'), Block = ref1.Block, Assign = ref1.Assign, Value = ref1.Value, Literal = ref1.Literal;
|
||||
try {
|
||||
tokens = CoffeeScript.tokens(input);
|
||||
|
|
|
@ -10,9 +10,12 @@ path = require 'path'
|
|||
{parser} = require './parser'
|
||||
helpers = require './helpers'
|
||||
SourceMap = require './sourcemap'
|
||||
# Require `package.json`, which is two levels above this file, as this file is
|
||||
# evaluated from `lib/coffee-script`.
|
||||
packageJson = require '../../package.json'
|
||||
|
||||
# The current CoffeeScript version number.
|
||||
exports.VERSION = '2.0.0-alpha'
|
||||
exports.VERSION = packageJson.version
|
||||
|
||||
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']
|
||||
|
||||
|
@ -280,83 +283,3 @@ parser.yy.parseError = (message, {token}) ->
|
|||
# from the lexer.
|
||||
helpers.throwSyntaxError "unexpected #{errorText}", errorLoc
|
||||
|
||||
# Based on http://v8.googlecode.com/svn/branches/bleeding_edge/src/messages.js
|
||||
# Modified to handle sourceMap
|
||||
formatSourcePosition = (frame, getSourceMapping) ->
|
||||
fileName = undefined
|
||||
fileLocation = ''
|
||||
|
||||
if frame.isNative()
|
||||
fileLocation = "native"
|
||||
else
|
||||
if frame.isEval()
|
||||
fileName = frame.getScriptNameOrSourceURL()
|
||||
fileLocation = "#{frame.getEvalOrigin()}, " unless fileName
|
||||
else
|
||||
fileName = frame.getFileName()
|
||||
|
||||
fileName or= "<anonymous>"
|
||||
|
||||
line = frame.getLineNumber()
|
||||
column = frame.getColumnNumber()
|
||||
|
||||
# Check for a sourceMap position
|
||||
source = getSourceMapping fileName, line, column
|
||||
fileLocation =
|
||||
if source
|
||||
"#{fileName}:#{source[0]}:#{source[1]}"
|
||||
else
|
||||
"#{fileName}:#{line}:#{column}"
|
||||
|
||||
functionName = frame.getFunctionName()
|
||||
isConstructor = frame.isConstructor()
|
||||
isMethodCall = not (frame.isToplevel() or isConstructor)
|
||||
|
||||
if isMethodCall
|
||||
methodName = frame.getMethodName()
|
||||
typeName = frame.getTypeName()
|
||||
|
||||
if functionName
|
||||
tp = as = ''
|
||||
if typeName and functionName.indexOf typeName
|
||||
tp = "#{typeName}."
|
||||
if methodName and functionName.indexOf(".#{methodName}") isnt functionName.length - methodName.length - 1
|
||||
as = " [as #{methodName}]"
|
||||
|
||||
"#{tp}#{functionName}#{as} (#{fileLocation})"
|
||||
else
|
||||
"#{typeName}.#{methodName or '<anonymous>'} (#{fileLocation})"
|
||||
else if isConstructor
|
||||
"new #{functionName or '<anonymous>'} (#{fileLocation})"
|
||||
else if functionName
|
||||
"#{functionName} (#{fileLocation})"
|
||||
else
|
||||
fileLocation
|
||||
|
||||
# Map of filenames -> sourceMap object.
|
||||
sourceMaps = {}
|
||||
|
||||
# Generates the source map for a coffee file and stores it in the local cache variable.
|
||||
getSourceMap = (filename) ->
|
||||
return sourceMaps[filename] if sourceMaps[filename]
|
||||
for ext in exports.FILE_EXTENSIONS
|
||||
if helpers.ends filename, ext
|
||||
answer = exports._compileFile filename, true
|
||||
return sourceMaps[filename] = answer.sourceMap
|
||||
return null
|
||||
|
||||
# Based on [michaelficarra/CoffeeScriptRedux](http://goo.gl/ZTx1p)
|
||||
# NodeJS / V8 have no support for transforming positions in stack traces using
|
||||
# sourceMap, so we must monkey-patch Error to display CoffeeScript source
|
||||
# positions.
|
||||
Error.prepareStackTrace = (err, stack) ->
|
||||
getSourceMapping = (filename, line, column) ->
|
||||
sourceMap = getSourceMap filename
|
||||
answer = sourceMap.sourceLocation [line - 1, column - 1] if sourceMap
|
||||
if answer then [answer[0] + 1, answer[1] + 1] else null
|
||||
|
||||
frames = for frame in stack
|
||||
break if frame.getFunction() is exports.run
|
||||
" at #{formatSourcePosition frame, getSourceMapping}"
|
||||
|
||||
"#{err.toString()}\n#{frames.join '\n'}\n"
|
||||
|
|
|
@ -15,6 +15,9 @@ replDefaults =
|
|||
# Node's REPL sends the input ending with a newline and then wrapped in
|
||||
# parens. Unwrap all that.
|
||||
input = input.replace /^\(([\s\S]*)\n\)$/m, '$1'
|
||||
# Node's REPL v6.9.1+ sends the input wrapped in a try/catch statement.
|
||||
# Unwrap that too.
|
||||
input = input.replace /^\s*try\s*{([\s\S]*)}\s*catch.*$/m, '$1'
|
||||
|
||||
# Require AST nodes to do some AST manipulation.
|
||||
{Block, Assign, Value, Literal} = require './nodes'
|
||||
|
|
|
@ -45,17 +45,6 @@ if require?
|
|||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
|
||||
test "patchStackTrace line patching", ->
|
||||
err = new Error 'error'
|
||||
ok err.stack.match /test[\/\\]error_messages\.coffee:\d+:\d+\b/
|
||||
|
||||
test "patchStackTrace stack prelude consistent with V8", ->
|
||||
err = new Error
|
||||
ok err.stack.match /^Error\n/ # Notice no colon when no message.
|
||||
|
||||
err = new Error 'error'
|
||||
ok err.stack.match /^Error: error\n/
|
||||
|
||||
test "#2849: compilation error in a require()d file", ->
|
||||
# Create a temporary file to require().
|
||||
ok not fs.existsSync 'test/syntax-error.coffee'
|
||||
|
|
Loading…
Add table
Reference in a new issue