Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9df3e6a

Browse files
committed
first step towards requiring #{ ... } interpolation -- removing naked interps from the compiler.
1 parent b1f7d5e commit 9df3e6a

28 files changed

Lines changed: 284 additions & 300 deletions

Cakefile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ run = (args) ->
1616

1717
# Log a message with a color.
1818
log = (message, color, explanation) ->
19-
puts "#color#message#reset #{explanation or ''}"
19+
puts color + message + reset + ' ' + (explanation or '')
2020

2121
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
2222

2323
task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
2424
base = options.prefix or '/usr/local'
25-
lib = "#base/lib/coffee-script"
26-
bin = "#base/bin"
25+
lib = "#{base}/lib/coffee-script"
26+
bin = "#{base}/bin"
2727
node = "~/.node_libraries/coffee-script"
28-
puts "Installing CoffeeScript to #lib"
29-
puts "Linking to #node"
30-
puts "Linking 'coffee' to #bin/coffee"
28+
puts "Installing CoffeeScript to #{lib}"
29+
puts "Linking to #{node}"
30+
puts "Linking 'coffee' to #{bin}/coffee"
3131
exec([
32-
"mkdir -p #lib #bin"
33-
"cp -rf bin lib LICENSE README package.json src #lib"
34-
"ln -sf #lib/bin/coffee #bin/coffee"
35-
"ln -sf #lib/bin/cake #bin/cake"
32+
"mkdir -p #{lib} #{bin}"
33+
"cp -rf bin lib LICENSE README package.json src #{lib}"
34+
"ln -sf #{lib}/bin/coffee #{bin}/coffee"
35+
"ln -sf #{lib}/bin/cake #{bin}/cake"
3636
"mkdir -p ~/.node_libraries"
37-
"ln -sf #lib/lib #node"
37+
"ln -sf #{lib}/lib #{node}"
3838
].join(' && '), (err, stdout, stderr) ->
3939
if err then print stderr else log 'done', green
4040
)
@@ -103,9 +103,9 @@ task 'test', 'run the CoffeeScript language test suite', ->
103103
}
104104
process.on 'exit', ->
105105
time = ((new Date - startTime) / 1000).toFixed(2)
106-
message = "passed #passedTests tests in #time seconds#reset"
106+
message = "passed #{passedTests} tests in #{time} seconds#{reset}"
107107
if failedTests
108-
log "failed #failedTests and #message", red
108+
log "failed #{failedTests} and #{message}", red
109109
else
110110
log message, green
111111
fs.readdir 'test', (err, files) ->
@@ -117,4 +117,4 @@ task 'test', 'run the CoffeeScript language test suite', ->
117117
CoffeeScript.run code.toString(), {fileName}
118118
catch err
119119
failedTests += 1
120-
log "failed #fileName", red, '\n' + err.stack.toString()
120+
log "failed #{fileName}", red, '\n' + err.stack.toString()

documentation/coffee/cake_tasks.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ task 'build:parser', 'rebuild the Jison parser', ->
66
require 'jison'
77
code = require('./lib/grammar').parser.generate()
88
dir = options.output or 'lib'
9-
fs.writeFile "#dir/parser.js", code
9+
fs.writeFile "#{dir}/parser.js", code
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
author = "Wittgenstein"
2-
quote = "A picture is a fact. -- #author"
2+
quote = "A picture is a fact. -- #{author}"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sentence = "#{ 22 / 7 } is a decent approximation of π"
22

33
sep = "[.\\/\\- ]"
4-
dates = /\d+#sep\d+#sep\d+/g
4+
dates = /\d+#{sep}\d+#{sep}\d+/g
55

66

lib/cake.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@
7070
}
7171
return _b;
7272
})().join('') : '';
73-
desc = task.description ? ("# " + task.description) : '';
74-
puts("cake " + name + spaces + " " + desc);
73+
desc = task.description ? ("# " + (task.description)) : '';
74+
puts(("cake " + (name) + (spaces) + " " + (desc)));
7575
}
7676
if (switches.length) {
7777
return puts(oparse.help());
7878
}
7979
};
8080
missingTask = function(task) {
81-
puts("No such task: \"" + task + "\"");
81+
puts(("No such task: \"" + (task) + "\""));
8282
return process.exit(1);
8383
};
8484
})();

lib/coffee-script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
return (parser.parse(lexer.tokenize(code))).compile(options);
2424
} catch (err) {
2525
if (options.fileName) {
26-
err.message = ("In " + options.fileName + ", " + err.message);
26+
err.message = ("In " + (options.fileName) + ", " + (err.message));
2727
}
2828
throw err;
2929
}

lib/command.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
compile = function(source, topLevel) {
5959
return path.exists(source, function(exists) {
6060
if (!(exists)) {
61-
throw new Error("File not found: " + source);
61+
throw new Error(("File not found: " + (source)));
6262
}
6363
return fs.stat(source, function(err, stats) {
6464
if (stats.isDirectory()) {
@@ -155,12 +155,12 @@
155155
}
156156
return fs.writeFile(jsPath, js, function(err) {
157157
if (options.compile && options.watch) {
158-
return puts("Compiled " + source);
158+
return puts(("Compiled " + (source)));
159159
}
160160
});
161161
};
162162
return path.exists(dir, function(exists) {
163-
return exists ? compile() : exec(("mkdir -p " + dir), compile);
163+
return exists ? compile() : exec(("mkdir -p " + (dir)), compile);
164164
});
165165
};
166166
lint = function(js) {
@@ -184,7 +184,7 @@
184184
_f = [token[0], token[1].toString().replace(/\n/, '\\n')];
185185
tag = _f[0];
186186
value = _f[1];
187-
return "[" + tag + " " + value + "]";
187+
return "[" + (tag) + " " + (value) + "]";
188188
})());
189189
}
190190
return _b;
@@ -213,7 +213,7 @@
213213
return process.exit(0);
214214
};
215215
version = function() {
216-
puts("CoffeeScript version " + CoffeeScript.VERSION);
216+
puts(("CoffeeScript version " + (CoffeeScript.VERSION)));
217217
return process.exit(0);
218218
};
219219
})();

lib/grammar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
if (!(action)) {
99
return [patternString, '$$ = $1;', options];
1010
}
11-
action = (match = (action + '').match(unwrap)) ? match[1] : ("(" + action + "())");
12-
return [patternString, ("$$ = " + action + ";"), options];
11+
action = (match = (action + '').match(unwrap)) ? match[1] : ("(" + (action) + "())");
12+
return [patternString, ("$$ = " + (action) + ";"), options];
1313
};
1414
grammar = {
1515
Root: [

lib/lexer.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
if (include(JS_FORBIDDEN, id)) {
9090
if (forcedIdentifier) {
9191
tag = 'STRING';
92-
id = ("\"" + id + "\"");
92+
id = ("\"" + (id) + "\"");
9393
if (forcedIdentifier === 'accessor') {
9494
close_index = true;
9595
if (this.tag() !== '@') {
@@ -146,7 +146,7 @@
146146
doc = this.sanitizeHeredoc(match[2] || match[4], {
147147
quote: quote
148148
});
149-
this.interpolateString(("" + quote + doc + quote), {
149+
this.interpolateString(quote + doc + quote, {
150150
heredoc: true
151151
});
152152
this.line += count(match[1], "\n");
@@ -204,11 +204,11 @@
204204
return '\\' + escaped;
205205
});
206206
this.tokens = this.tokens.concat([['(', '('], ['NEW', 'new'], ['IDENTIFIER', 'RegExp'], ['CALL_START', '(']]);
207-
this.interpolateString(("\"" + str + "\""), {
207+
this.interpolateString(("\"" + (str) + "\""), {
208208
escapeQuotes: true
209209
});
210210
if (flags) {
211-
this.tokens.splice(this.tokens.length, 0, [',', ','], ['STRING', ("\"" + flags + "\"")]);
211+
this.tokens.splice(this.tokens.length, 0, [',', ','], ['STRING', ("\"" + (flags) + "\"")]);
212212
}
213213
this.tokens.splice(this.tokens.length, 0, [')', ')'], [')', ')']);
214214
} else {
@@ -377,7 +377,7 @@
377377
if (options.herecomment) {
378378
return doc;
379379
}
380-
return doc.replace(MULTILINER, "\\n").replace(new RegExp(options.quote, 'g'), ("\\" + options.quote));
380+
return doc.replace(MULTILINER, "\\n").replace(new RegExp(options.quote, 'g'), ("\\" + (options.quote)));
381381
};
382382
Lexer.prototype.tagParameters = function() {
383383
var _d, i, tok;
@@ -405,7 +405,7 @@
405405
return this.outdentToken(this.indent);
406406
};
407407
Lexer.prototype.identifierError = function(word) {
408-
throw new Error(("SyntaxError: Reserved word \"" + word + "\" on line " + (this.line + 1)));
408+
throw new Error(("SyntaxError: Reserved word \"" + (word) + "\" on line " + (this.line + 1)));
409409
};
410410
Lexer.prototype.assignmentError = function() {
411411
throw new Error(("SyntaxError: Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned"));
@@ -476,21 +476,21 @@
476476
interp = ("this." + (interp.substring(1)));
477477
}
478478
if (pi < i) {
479-
tokens.push(['STRING', ("" + quote + (str.substring(pi, i)) + quote)]);
479+
tokens.push(['STRING', quote + str.substring(pi, i) + quote]);
480480
}
481481
tokens.push(['IDENTIFIER', interp]);
482482
i += group.length - 1;
483483
pi = i + 1;
484484
} else if ((expr = this.balancedString(str.substring(i), [['#{', '}']]))) {
485485
if (pi < i) {
486-
tokens.push(['STRING', ("" + quote + (str.substring(pi, i)) + quote)]);
486+
tokens.push(['STRING', quote + str.substring(pi, i) + quote]);
487487
}
488488
inner = expr.substring(2, expr.length - 1);
489489
if (inner.length) {
490490
if (options.heredoc) {
491491
inner = inner.replace(new RegExp('\\\\' + quote, 'g'), quote);
492492
}
493-
nested = lexer.tokenize(("(" + inner + ")"), {
493+
nested = lexer.tokenize(("(" + (inner) + ")"), {
494494
line: this.line
495495
});
496496
_f = nested;
@@ -501,15 +501,15 @@
501501
nested.pop();
502502
tokens.push(['TOKENS', nested]);
503503
} else {
504-
tokens.push(['STRING', ("" + quote + quote)]);
504+
tokens.push(['STRING', quote + quote]);
505505
}
506506
i += expr.length - 1;
507507
pi = i + 1;
508508
}
509509
i += 1;
510510
}
511511
if (pi < i && pi < str.length - 1) {
512-
tokens.push(['STRING', ("" + quote + (str.substring(pi, i)) + quote)]);
512+
tokens.push(['STRING', quote + str.substring(pi, i) + quote]);
513513
}
514514
if (!(tokens[0][0] === 'STRING')) {
515515
tokens.unshift(['STRING', '""']);
@@ -528,7 +528,7 @@
528528
this.tokens = this.tokens.concat(value);
529529
} else if (tag === 'STRING' && options.escapeQuotes) {
530530
escaped = value.substring(1, value.length - 1).replace(/"/g, '\\"');
531-
this.token(tag, ("\"" + escaped + "\""));
531+
this.token(tag, ("\"" + (escaped) + "\""));
532532
} else {
533533
this.token(tag, value);
534534
}

0 commit comments

Comments
 (0)