mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Merge pull request #1793 from TrevorBurnham/header
Adding header to generated JS (#1778)
This commit is contained in:
commit
447ce82721
16 changed files with 33 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var CoffeeScript, runScripts;
|
var CoffeeScript, runScripts;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
|
||||||
|
|
||||||
|
@ -65,8 +66,9 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
printTasks = function() {
|
printTasks = function() {
|
||||||
var cakefilePath, desc, name, spaces, task;
|
var cakefilePath, desc, name, relative, spaces, task;
|
||||||
cakefilePath = path.join(path.relative(__originalDirname, process.cwd()), 'Cakefile');
|
relative = path.relative || path.resolve;
|
||||||
|
cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
|
||||||
console.log("" + cakefilePath + " defines the following tasks:\n");
|
console.log("" + cakefilePath + " defines the following tasks:\n");
|
||||||
for (name in tasks) {
|
for (name in tasks) {
|
||||||
task = tasks[name];
|
task = tasks[name];
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var Lexer, RESERVED, compile, fs, lexer, parser, path, vm, _ref,
|
var Lexer, RESERVED, compile, fs, lexer, parser, path, vm, _ref,
|
||||||
__hasProp = Object.prototype.hasOwnProperty;
|
__hasProp = Object.prototype.hasOwnProperty;
|
||||||
|
@ -33,17 +34,20 @@
|
||||||
exports.helpers = require('./helpers');
|
exports.helpers = require('./helpers');
|
||||||
|
|
||||||
exports.compile = compile = function(code, options) {
|
exports.compile = compile = function(code, options) {
|
||||||
var merge;
|
var header, js, merge;
|
||||||
if (options == null) options = {};
|
if (options == null) options = {};
|
||||||
merge = exports.helpers.merge;
|
merge = exports.helpers.merge;
|
||||||
try {
|
try {
|
||||||
return (parser.parse(lexer.tokenize(code))).compile(merge({}, options));
|
js = (parser.parse(lexer.tokenize(code))).compile(options);
|
||||||
|
if (!options.header) return js;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (options.filename) {
|
if (options.filename) {
|
||||||
err.message = "In " + options.filename + ", " + err.message;
|
err.message = "In " + options.filename + ", " + err.message;
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
header = "Generated by CoffeeScript " + this.VERSION;
|
||||||
|
return "// " + header + "\n" + js;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.tokens = function(code, options) {
|
exports.tokens = function(code, options) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
|
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
|
||||||
|
|
||||||
|
@ -406,7 +407,8 @@
|
||||||
compileOptions = function(filename) {
|
compileOptions = function(filename) {
|
||||||
return {
|
return {
|
||||||
filename: filename,
|
filename: filename,
|
||||||
bare: opts.bare
|
bare: opts.bare,
|
||||||
|
header: opts.compile
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var extend, flatten;
|
var extend, flatten;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var key, val, _ref;
|
var key, val, _ref;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref2,
|
var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref2,
|
||||||
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref,
|
var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref,
|
||||||
__hasProp = Object.prototype.hasOwnProperty,
|
__hasProp = Object.prototype.hasOwnProperty,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments;
|
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, REPL_PROMPT_MULTILINE, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, getCompletions, inspect, multilineMode, readline, repl, stdin, stdout;
|
var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, REPL_PROMPT_MULTILINE, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, getCompletions, inspect, multilineMode, readline, repl, stdin, stdout;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref,
|
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref,
|
||||||
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Generated by CoffeeScript 1.2.1-pre
|
||||||
(function() {
|
(function() {
|
||||||
var Scope, extend, last, _ref;
|
var Scope, extend, last, _ref;
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,13 @@ exports.helpers = require './helpers'
|
||||||
exports.compile = compile = (code, options = {}) ->
|
exports.compile = compile = (code, options = {}) ->
|
||||||
{merge} = exports.helpers
|
{merge} = exports.helpers
|
||||||
try
|
try
|
||||||
(parser.parse lexer.tokenize code).compile merge {}, options
|
js = (parser.parse lexer.tokenize code).compile options
|
||||||
|
return js unless options.header
|
||||||
catch err
|
catch err
|
||||||
err.message = "In #{options.filename}, #{err.message}" if options.filename
|
err.message = "In #{options.filename}, #{err.message}" if options.filename
|
||||||
throw err
|
throw err
|
||||||
|
header = "Generated by CoffeeScript #{@VERSION}"
|
||||||
|
"// #{header}\n#{js}"
|
||||||
|
|
||||||
# Tokenize a string of CoffeeScript code, and return the array of tokens.
|
# Tokenize a string of CoffeeScript code, and return the array of tokens.
|
||||||
exports.tokens = (code, options) ->
|
exports.tokens = (code, options) ->
|
||||||
|
|
|
@ -313,7 +313,8 @@ parseOptions = ->
|
||||||
return
|
return
|
||||||
|
|
||||||
# The compile-time options to pass to the CoffeeScript compiler.
|
# The compile-time options to pass to the CoffeeScript compiler.
|
||||||
compileOptions = (filename) -> {filename, bare: opts.bare}
|
compileOptions = (filename) ->
|
||||||
|
{filename, bare: opts.bare, header: opts.compile}
|
||||||
|
|
||||||
# Start up a new Node.js instance with the arguments in `--nodejs` passed to
|
# Start up a new Node.js instance with the arguments in `--nodejs` passed to
|
||||||
# the `node` binary, preserving the other options.
|
# the `node` binary, preserving the other options.
|
||||||
|
|
|
@ -13,6 +13,10 @@ test "--bare", ->
|
||||||
eq -1, CoffeeScript.compile('x = y', bare: on).indexOf 'function'
|
eq -1, CoffeeScript.compile('x = y', bare: on).indexOf 'function'
|
||||||
ok 'passed' is CoffeeScript.eval '"passed"', bare: on, filename: 'test'
|
ok 'passed' is CoffeeScript.eval '"passed"', bare: on, filename: 'test'
|
||||||
|
|
||||||
|
test "header (#1778)", ->
|
||||||
|
header = "// Generated by CoffeeScript #{CoffeeScript.VERSION}\n"
|
||||||
|
eq 0, CoffeeScript.compile('x = y', header: on).indexOf header
|
||||||
|
|
||||||
test "multiple generated references", ->
|
test "multiple generated references", ->
|
||||||
a = {b: []}
|
a = {b: []}
|
||||||
a.b[true] = -> this == a.b
|
a.b[true] = -> this == a.b
|
||||||
|
|
Loading…
Add table
Reference in a new issue