mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 02:51:25 -05:00
fixing exports for the browser
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -13,8 +13,9 @@
|
|||||||
Lexer = require('lexer').Lexer;
|
Lexer = require('lexer').Lexer;
|
||||||
parser = require('parser').parser;
|
parser = require('parser').parser;
|
||||||
} else {
|
} else {
|
||||||
parser = exports.parser;
|
|
||||||
this.exports = (this.CoffeeScript = {});
|
this.exports = (this.CoffeeScript = {});
|
||||||
|
Lexer = this.Lexer;
|
||||||
|
parser = this.parser;
|
||||||
}
|
}
|
||||||
// The current CoffeeScript version number.
|
// The current CoffeeScript version number.
|
||||||
exports.VERSION = '0.5.5';
|
exports.VERSION = '0.5.5';
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
(function(){
|
(function(){
|
||||||
|
var balanced_string, compact, count, del, flatten, include, merge, starts;
|
||||||
var __hasProp = Object.prototype.hasOwnProperty;
|
var __hasProp = Object.prototype.hasOwnProperty;
|
||||||
// This file contains the common helper functions that we'd like to share among
|
// This file contains the common helper functions that we'd like to share among
|
||||||
// the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten
|
// the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten
|
||||||
@@ -8,15 +9,15 @@
|
|||||||
this.exports = this;
|
this.exports = this;
|
||||||
}
|
}
|
||||||
// Does a list include a value?
|
// Does a list include a value?
|
||||||
exports.include = function include(list, value) {
|
exports.include = (include = function include(list, value) {
|
||||||
return list.indexOf(value) >= 0;
|
return list.indexOf(value) >= 0;
|
||||||
};
|
});
|
||||||
// Peek at the beginning of a given string to see if it matches a sequence.
|
// Peek at the beginning of a given string to see if it matches a sequence.
|
||||||
exports.starts = function starts(string, literal, start) {
|
exports.starts = (starts = function starts(string, literal, start) {
|
||||||
return string.substring(start, (start || 0) + literal.length) === literal;
|
return string.substring(start, (start || 0) + literal.length) === literal;
|
||||||
};
|
});
|
||||||
// Trim out all falsy values from an array.
|
// Trim out all falsy values from an array.
|
||||||
exports.compact = function compact(array) {
|
exports.compact = (compact = function compact(array) {
|
||||||
var _a, _b, _c, _d, item;
|
var _a, _b, _c, _d, item;
|
||||||
_a = []; _b = array;
|
_a = []; _b = array;
|
||||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||||
@@ -26,9 +27,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _a;
|
return _a;
|
||||||
};
|
});
|
||||||
// Count the number of occurences of a character in a string.
|
// Count the number of occurences of a character in a string.
|
||||||
exports.count = function count(string, letter) {
|
exports.count = (count = function count(string, letter) {
|
||||||
var num, pos;
|
var num, pos;
|
||||||
num = 0;
|
num = 0;
|
||||||
pos = string.indexOf(letter);
|
pos = string.indexOf(letter);
|
||||||
@@ -37,11 +38,11 @@
|
|||||||
pos = string.indexOf(letter, pos + 1);
|
pos = string.indexOf(letter, pos + 1);
|
||||||
}
|
}
|
||||||
return num;
|
return num;
|
||||||
};
|
});
|
||||||
// Merge objects, returning a fresh copy with attributes from both sides.
|
// Merge objects, returning a fresh copy with attributes from both sides.
|
||||||
// Used every time `BaseNode#compile` is called, to allow properties in the
|
// Used every time `BaseNode#compile` is called, to allow properties in the
|
||||||
// options hash to propagate down the tree without polluting other branches.
|
// options hash to propagate down the tree without polluting other branches.
|
||||||
exports.merge = function merge(options, overrides) {
|
exports.merge = (merge = function merge(options, overrides) {
|
||||||
var _a, _b, fresh, key, val;
|
var _a, _b, fresh, key, val;
|
||||||
fresh = {};
|
fresh = {};
|
||||||
_a = options;
|
_a = options;
|
||||||
@@ -57,10 +58,10 @@
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
return fresh;
|
return fresh;
|
||||||
};
|
});
|
||||||
// Return a completely flattened version of an array. Handy for getting a
|
// Return a completely flattened version of an array. Handy for getting a
|
||||||
// list of `children` from the nodes.
|
// list of `children` from the nodes.
|
||||||
exports.flatten = function flatten(array) {
|
exports.flatten = (flatten = function flatten(array) {
|
||||||
var _a, _b, _c, item, memo;
|
var _a, _b, _c, item, memo;
|
||||||
memo = [];
|
memo = [];
|
||||||
_a = array;
|
_a = array;
|
||||||
@@ -69,27 +70,27 @@
|
|||||||
item instanceof Array ? (memo = memo.concat(item)) : memo.push(item);
|
item instanceof Array ? (memo = memo.concat(item)) : memo.push(item);
|
||||||
}
|
}
|
||||||
return memo;
|
return memo;
|
||||||
};
|
});
|
||||||
// Delete a key from an object, returning the value. Useful when a node is
|
// Delete a key from an object, returning the value. Useful when a node is
|
||||||
// looking for a particular method in an options hash.
|
// looking for a particular method in an options hash.
|
||||||
exports.del = function del(obj, key) {
|
exports.del = (del = function del(obj, key) {
|
||||||
var val;
|
var val;
|
||||||
val = obj[key];
|
val = obj[key];
|
||||||
delete obj[key];
|
delete obj[key];
|
||||||
return val;
|
return val;
|
||||||
};
|
});
|
||||||
// Matches a balanced group such as a single or double-quoted string. Pass in
|
// Matches a balanced group such as a single or double-quoted string. Pass in
|
||||||
// a series of delimiters, all of which must be nested correctly within the
|
// a series of delimiters, all of which must be nested correctly within the
|
||||||
// contents of the string. This method allows us to have strings within
|
// contents of the string. This method allows us to have strings within
|
||||||
// interpolations within strings, ad infinitum.
|
// interpolations within strings, ad infinitum.
|
||||||
exports.balanced_string = function balanced_string(str, delimited, options) {
|
exports.balanced_string = (balanced_string = function balanced_string(str, delimited, options) {
|
||||||
var _a, _b, _c, _d, close, i, levels, open, pair, slash;
|
var _a, _b, _c, _d, close, i, levels, open, pair, slash;
|
||||||
options = options || {};
|
options = options || {};
|
||||||
slash = delimited[0][0] === '/';
|
slash = delimited[0][0] === '/';
|
||||||
levels = [];
|
levels = [];
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < str.length) {
|
while (i < str.length) {
|
||||||
if (levels.length && exports.starts(str, '\\', i)) {
|
if (levels.length && starts(str, '\\', i)) {
|
||||||
i += 1;
|
i += 1;
|
||||||
} else {
|
} else {
|
||||||
_a = delimited;
|
_a = delimited;
|
||||||
@@ -98,21 +99,21 @@
|
|||||||
_d = pair;
|
_d = pair;
|
||||||
open = _d[0];
|
open = _d[0];
|
||||||
close = _d[1];
|
close = _d[1];
|
||||||
if (levels.length && exports.starts(str, close, i) && levels[levels.length - 1] === pair) {
|
if (levels.length && starts(str, close, i) && levels[levels.length - 1] === pair) {
|
||||||
levels.pop();
|
levels.pop();
|
||||||
i += close.length - 1;
|
i += close.length - 1;
|
||||||
if (!(levels.length)) {
|
if (!(levels.length)) {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (exports.starts(str, open, i)) {
|
} else if (starts(str, open, i)) {
|
||||||
levels.push(pair);
|
levels.push(pair);
|
||||||
i += open.length - 1;
|
i += open.length - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!levels.length || slash && exports.starts(str, '\n', i)) {
|
if (!levels.length || slash && starts(str, '\n', i)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
@@ -124,5 +125,5 @@
|
|||||||
throw new Error("SyntaxError: Unterminated " + (levels.pop()[0]) + " starting on line " + (this.line + 1));
|
throw new Error("SyntaxError: Unterminated " + (levels.pop()[0]) + " starting on line " + (this.line + 1));
|
||||||
}
|
}
|
||||||
return !i ? false : str.substring(0, i);
|
return !i ? false : str.substring(0, i);
|
||||||
};
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
process.mixin(require('./helpers'));
|
process.mixin(require('./helpers'));
|
||||||
} else {
|
} else {
|
||||||
this.exports = this;
|
this.exports = this;
|
||||||
|
Rewriter = this.Rewriter;
|
||||||
}
|
}
|
||||||
// The Lexer Class
|
// The Lexer Class
|
||||||
// ---------------
|
// ---------------
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ if process?
|
|||||||
Lexer: require('lexer').Lexer
|
Lexer: require('lexer').Lexer
|
||||||
parser: require('parser').parser
|
parser: require('parser').parser
|
||||||
else
|
else
|
||||||
parser: exports.parser
|
|
||||||
this.exports: this.CoffeeScript: {}
|
this.exports: this.CoffeeScript: {}
|
||||||
|
Lexer: this.Lexer
|
||||||
|
parser: this.parser
|
||||||
|
|
||||||
# The current CoffeeScript version number.
|
# The current CoffeeScript version number.
|
||||||
exports.VERSION: '0.5.5'
|
exports.VERSION: '0.5.5'
|
||||||
|
|||||||
@@ -6,18 +6,18 @@
|
|||||||
this.exports: this unless process?
|
this.exports: this unless process?
|
||||||
|
|
||||||
# Does a list include a value?
|
# Does a list include a value?
|
||||||
exports.include: (list, value) ->
|
exports.include: include: (list, value) ->
|
||||||
list.indexOf(value) >= 0
|
list.indexOf(value) >= 0
|
||||||
|
|
||||||
# Peek at the beginning of a given string to see if it matches a sequence.
|
# Peek at the beginning of a given string to see if it matches a sequence.
|
||||||
exports.starts: (string, literal, start) ->
|
exports.starts: starts: (string, literal, start) ->
|
||||||
string.substring(start, (start or 0) + literal.length) is literal
|
string.substring(start, (start or 0) + literal.length) is literal
|
||||||
|
|
||||||
# Trim out all falsy values from an array.
|
# Trim out all falsy values from an array.
|
||||||
exports.compact: (array) -> item for item in array when item
|
exports.compact: compact: (array) -> item for item in array when item
|
||||||
|
|
||||||
# Count the number of occurences of a character in a string.
|
# Count the number of occurences of a character in a string.
|
||||||
exports.count: (string, letter) ->
|
exports.count: count: (string, letter) ->
|
||||||
num: 0
|
num: 0
|
||||||
pos: string.indexOf(letter)
|
pos: string.indexOf(letter)
|
||||||
while pos isnt -1
|
while pos isnt -1
|
||||||
@@ -28,7 +28,7 @@ exports.count: (string, letter) ->
|
|||||||
# Merge objects, returning a fresh copy with attributes from both sides.
|
# Merge objects, returning a fresh copy with attributes from both sides.
|
||||||
# Used every time `BaseNode#compile` is called, to allow properties in the
|
# Used every time `BaseNode#compile` is called, to allow properties in the
|
||||||
# options hash to propagate down the tree without polluting other branches.
|
# options hash to propagate down the tree without polluting other branches.
|
||||||
exports.merge: (options, overrides) ->
|
exports.merge: merge: (options, overrides) ->
|
||||||
fresh: {}
|
fresh: {}
|
||||||
(fresh[key]: val) for key, val of options
|
(fresh[key]: val) for key, val of options
|
||||||
(fresh[key]: val) for key, val of overrides if overrides
|
(fresh[key]: val) for key, val of overrides if overrides
|
||||||
@@ -36,7 +36,7 @@ exports.merge: (options, overrides) ->
|
|||||||
|
|
||||||
# Return a completely flattened version of an array. Handy for getting a
|
# Return a completely flattened version of an array. Handy for getting a
|
||||||
# list of `children` from the nodes.
|
# list of `children` from the nodes.
|
||||||
exports.flatten: (array) ->
|
exports.flatten: flatten: (array) ->
|
||||||
memo: []
|
memo: []
|
||||||
for item in array
|
for item in array
|
||||||
if item instanceof Array then memo: memo.concat(item) else memo.push(item)
|
if item instanceof Array then memo: memo.concat(item) else memo.push(item)
|
||||||
@@ -44,7 +44,7 @@ exports.flatten: (array) ->
|
|||||||
|
|
||||||
# Delete a key from an object, returning the value. Useful when a node is
|
# Delete a key from an object, returning the value. Useful when a node is
|
||||||
# looking for a particular method in an options hash.
|
# looking for a particular method in an options hash.
|
||||||
exports.del: (obj, key) ->
|
exports.del: del: (obj, key) ->
|
||||||
val: obj[key]
|
val: obj[key]
|
||||||
delete obj[key]
|
delete obj[key]
|
||||||
val
|
val
|
||||||
@@ -53,27 +53,27 @@ exports.del: (obj, key) ->
|
|||||||
# a series of delimiters, all of which must be nested correctly within the
|
# a series of delimiters, all of which must be nested correctly within the
|
||||||
# contents of the string. This method allows us to have strings within
|
# contents of the string. This method allows us to have strings within
|
||||||
# interpolations within strings, ad infinitum.
|
# interpolations within strings, ad infinitum.
|
||||||
exports.balanced_string: (str, delimited, options) ->
|
exports.balanced_string: balanced_string: (str, delimited, options) ->
|
||||||
options ||= {}
|
options ||= {}
|
||||||
slash: delimited[0][0] is '/'
|
slash: delimited[0][0] is '/'
|
||||||
levels: []
|
levels: []
|
||||||
i: 0
|
i: 0
|
||||||
while i < str.length
|
while i < str.length
|
||||||
if levels.length and exports.starts str, '\\', i
|
if levels.length and starts str, '\\', i
|
||||||
i += 1
|
i += 1
|
||||||
else
|
else
|
||||||
for pair in delimited
|
for pair in delimited
|
||||||
[open, close]: pair
|
[open, close]: pair
|
||||||
if levels.length and exports.starts(str, close, i) and levels[levels.length - 1] is pair
|
if levels.length and starts(str, close, i) and levels[levels.length - 1] is pair
|
||||||
levels.pop()
|
levels.pop()
|
||||||
i += close.length - 1
|
i += close.length - 1
|
||||||
i += 1 unless levels.length
|
i += 1 unless levels.length
|
||||||
break
|
break
|
||||||
else if exports.starts str, open, i
|
else if starts str, open, i
|
||||||
levels.push(pair)
|
levels.push(pair)
|
||||||
i += open.length - 1
|
i += open.length - 1
|
||||||
break
|
break
|
||||||
break if not levels.length or slash and exports.starts str, '\n', i
|
break if not levels.length or slash and starts str, '\n', i
|
||||||
i += 1
|
i += 1
|
||||||
if levels.length
|
if levels.length
|
||||||
return false if slash
|
return false if slash
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ if process?
|
|||||||
process.mixin require './helpers'
|
process.mixin require './helpers'
|
||||||
else
|
else
|
||||||
this.exports: this
|
this.exports: this
|
||||||
|
Rewriter: this.Rewriter
|
||||||
|
|
||||||
# The Lexer Class
|
# The Lexer Class
|
||||||
# ---------------
|
# ---------------
|
||||||
|
|||||||
Reference in New Issue
Block a user