Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ task "dist", "Generate dist/eco.js", ->
"strscan": read "node_modules/strscan/lib/strscan.js"
"coffee-script": stub "CoffeeScript"

package = for name, source of modules
pkg = for name, source of modules
"""
'#{name}': function(module, require, exports) {
#{source}
Expand Down Expand Up @@ -89,12 +89,12 @@ task "dist", "Generate dist/eco.js", ->
}
};
})({
#{package.join ',\n'}
#{pkg.join ',\n'}
})('eco');
"""

try
fs.mkdirSync "#{__dirname}/dist", 0755
fs.mkdirSync "#{__dirname}/dist", 0o755
catch err

fs.writeFileSync "#{__dirname}/dist/eco.js", "#{header}\n#{source}"
83 changes: 59 additions & 24 deletions lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/compiler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion lib/preprocessor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions lib/scanner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/command.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ printUsage = ->
process.exit 1

printVersion = ->
package = JSON.parse fs.readFileSync __dirname + "/../package.json", "utf8"
console.error "Eco version #{package.version}"
pkg = JSON.parse fs.readFileSync __dirname + "/../package.json", "utf8"
console.error "Eco version #{pkg.version}"
process.exit 0

preprocessArgs = (args) ->
Expand Down
4 changes: 4 additions & 0 deletions src/preprocessor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ module.exports = class Preprocessor

printString: (string) ->
if string.length
string = string
.replace(/\s+</g, '<')
.replace(/>\s+/g, '>')
@record "__out.push #{util.inspectString string}"

beginCode: (options) ->
@options = options

recordCode: (code) ->
code = code.replace /\s+/g, ' '
if code isnt "end"
if @options.print
if @options.safe
Expand Down
14 changes: 4 additions & 10 deletions src/scanner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
module.exports = class Scanner
@modePatterns:
data: /(.*?)(<%%|<%\s*(\#)|<%(([=-])?)|\n|$)/
code: /(.*?)((((:|(->|=>))\s*))?%>|\n|$)/
comment: /(.*?)(%>|\n|$)/
code: /([\s\S]*?)((((:|(->|=>))\s*))?%>|$)/
comment: /([\s\S]*?)(%>|$)/

@dedentablePattern: /^(end|when|else|catch|finally)(?:\W|$)/

Expand Down Expand Up @@ -73,10 +73,7 @@ module.exports = class Scanner
callback ["beginCode", print: @directive?, safe: @directive is "-"]

scanCode: (callback) ->
if @tail is "\n"
callback ["fail", "unexpected newline in code block"]

else if @tail
if @tail
@mode = "data"
code = trim @flush()
code += " #{@arrow}" if @arrow
Expand All @@ -86,10 +83,7 @@ module.exports = class Scanner
callback ["indent", @arrow] if @directive

scanComment: (callback) ->
if @tail is "\n"
callback ["fail", "unexpected newline in code block"]

else if @tail
if @tail
@mode = "data"
@buffer = ""

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/newlines.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func { foo: bar }
__out.push '\n'
3 changes: 3 additions & 0 deletions test/fixtures/newlines.eco
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% func {
foo: bar
} %>
Loading