Skip to content

Commit

Permalink
merge in latest csr
Browse files Browse the repository at this point in the history
  • Loading branch information
ghempton committed Feb 25, 2014
2 parents f016fb1 + cd67139 commit 2134700
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -10,7 +10,7 @@ ROOT = $(shell pwd)
EMBER_SCRIPT = ./bin/ember-script --js --bare
COFFEE = node_modules/.bin/coffee --js --bare
PEGJS = node_modules/.bin/pegjs --cache --export-var 'module.exports'
MOCHA = node_modules/.bin/mocha --compilers coffee:./register -u tdd
MOCHA = node_modules/.bin/mocha --compilers em:./register -u tdd
CJSIFY = node_modules/.bin/cjsify --export EmberScript
MINIFIER = node_modules/.bin/esmangle

Expand Down Expand Up @@ -68,7 +68,7 @@ lib/%.min.js: lib/%.js lib/coffee-script
$(MINIFIER) <"$<" >"$@"


.PHONY: test coverage install loc clean
.PHONY: default all build parser browser min minify test coverage install loc clean


test:
Expand Down
14 changes: 12 additions & 2 deletions lib/compiler.js

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

23 changes: 21 additions & 2 deletions lib/helpers.js

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

17 changes: 15 additions & 2 deletions lib/module.js

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

2 changes: 1 addition & 1 deletion lib/parser.js

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

45 changes: 20 additions & 25 deletions lib/register.js

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

4 changes: 2 additions & 2 deletions lib/run.js

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

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -32,8 +32,8 @@
},
"optionalDependencies": {
"esmangle": "~1.0.0",
"source-map": "0.1.11",
"escodegen": "~0.0.24",
"source-map": "0.1.x",
"escodegen": "~1.2.0",
"cscodegen": "git://github.com/michaelficarra/cscodegen.git#73fd7202ac086c26f18c9d56f025b18b3c6f5383"
},
"engines": {
Expand Down
13 changes: 12 additions & 1 deletion src/compiler.coffee
Expand Up @@ -901,7 +901,18 @@ class exports.Compiler
]
[CS.NativeMemberAccessOp, ({expression, compile}) ->
if hasSoak this then expr compile generateSoak this
else memberAccess expression, @memberName
else
access = memberAccess expression, @memberName
# manually calculate raw/position info for member name
if @raw
access.property.raw = @memberName
access.property.line = @line
offset = @raw.length - @memberName.length
access.property.column = @column + offset - 1
access.property.offset = @offset + offset - 1
@column += @expression.raw.length
@offset += @expression.raw.length
access
]
[CS.ProtoMemberAccessOp, CS.SoakedProtoMemberAccessOp, ({expression, compile}) ->
if hasSoak this then expr compile generateSoak this
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.pegjs
Expand Up @@ -214,7 +214,7 @@ var CS = require("./nodes"),
var o = new F;
// rather safely assumes access.op is returning non-Object
access.op.apply(o, [left].concat(access.operands));
return c(o.r(left.raw + access.raw), access);
return c(o.r(left.raw + access.raw), e);
}, e, accesses);
},
Expand Down
19 changes: 18 additions & 1 deletion src/helpers.coffee
Expand Up @@ -2,6 +2,21 @@
CS = require './nodes'


COLOURS =
red: '\x1B[31m'
green: '\x1B[32m'
yellow: '\x1B[33m'
blue: '\x1B[34m'
magenta: '\x1B[35m'
cyan: '\x1B[36m'

SUPPORTS_COLOUR =
process?.stderr?.isTTY and not process.env.NODE_DISABLE_COLORS

colourise = (colour, str) ->
if SUPPORTS_COLOUR then "#{COLOURS[colour]}#{str}\x1B[39m" else str


@numberLines = numberLines = (input, startLine = 1) ->
lines = input.split '\n'
padSize = "#{lines.length + startLine - 1}".length
Expand Down Expand Up @@ -29,12 +44,14 @@ cleanMarkers = (str) -> str.replace /[\uEFEF\uEFFE\uEFFF]/g, ''

@pointToErrorLocation = pointToErrorLocation = (source, line, column, numLinesOfContext = 3) ->
lines = source.split '\n'
lines.pop() unless lines[lines.length - 1]
# figure out which lines are needed for context
currentLineOffset = line - 1
startLine = currentLineOffset - numLinesOfContext
if startLine < 0 then startLine = 0
# get the context lines
preLines = lines[startLine..currentLineOffset]
preLines[preLines.length - 1] = colourise 'yellow', preLines[preLines.length - 1]
postLines = lines[currentLineOffset + 1 .. currentLineOffset + numLinesOfContext]
numberedLines = (numberLines (cleanMarkers [preLines..., postLines...].join '\n'), startLine + 1).split '\n'
preLines = numberedLines[0...preLines.length]
Expand All @@ -44,7 +61,7 @@ cleanMarkers = (str) -> str.replace /[\uEFEF\uEFFE\uEFFF]/g, ''
padSize = ((currentLineOffset + 1 + postLines.length).toString 10).length
[
preLines...
"#{(Array padSize + 1).join '^'} :~#{(Array column).join '~'}^"
"#{colourise 'red', (Array padSize + 1).join '^'} : #{(Array column).join ' '}#{colourise 'red', '^'}"
postLines...
].join '\n'

Expand Down
6 changes: 6 additions & 0 deletions src/module.coffee
Expand Up @@ -78,3 +78,9 @@ module.exports = CoffeeScript

if require.extensions?['.node']?
CoffeeScript.register = -> require './register'
# Throw error with deprecation warning when depending upon implicit `require.extensions` registration
for ext in ['.coffee', '.litcoffee']
require.extensions[ext] ?= ->
throw new Error """
Use CoffeeScript.register() or require the coffee-script-redux/register module to require #{ext} files.
"""
6 changes: 4 additions & 2 deletions src/register.coffee
Expand Up @@ -8,14 +8,14 @@ EmberScript = require './module'

module.exports = not require.extensions['.em']?

require.extensions['.em'] ?= (module, filename) ->
require.extensions['.em'] = (module, filename) ->
input = fs.readFileSync filename, 'utf8'
csAst = EmberScript.parse input, raw: yes
jsAst = EmberScript.compile csAst
js = EmberScript.js jsAst
runModule module, js, jsAst, filename

require.extensions['.litem'] ?= (module, filename) ->
require.extensions['.litem'] = (module, filename) ->
input = fs.readFileSync filename, 'utf8'
csAst = EmberScript.parse input, raw: yes, literate: yes
jsAst = EmberScript.compile csAst
Expand All @@ -34,3 +34,5 @@ unless fork.emPatched
options.execPath or= emBinary
fork file, args, options
child_process.fork.emPatched = yes

delete require.cache[__filename]
7 changes: 5 additions & 2 deletions src/run.coffee
Expand Up @@ -34,7 +34,7 @@ patchStackTrace = ->
mapString = Module._sourceMaps[filename]?()
if mapString
sourceMap = sourceFiles[filename] ?= new SourceMapConsumer mapString
sourceMap.originalPositionFor {line, column}
sourceMap.originalPositionFor {line, column: column - 1}

frames = for frame in stack
break if frame.getFunction() is exports.runMain
Expand Down Expand Up @@ -66,7 +66,10 @@ formatSourcePosition = (frame, getSourceMapping) ->
source = getSourceMapping fileName, line, column
fileLocation =
if source
"#{fileName}:#{source.line}:#{source.column + 1}, <js>:#{line}:#{column}"
if source.line?
"#{fileName}:#{source.line}:#{source.column + 1}, <js>:#{line}:#{column}"
else
"#{fileName} <js>:#{line}:#{column}"
else
"#{fileName}:#{line}:#{column}"

Expand Down
3 changes: 1 addition & 2 deletions test/cli-eval-errors.em
Expand Up @@ -9,9 +9,8 @@ suite 'Command line execution', ->
# Other module is not requires.main
eq stdout, "1 is main true\n0 is main false\n"

console.log stderr
ok stderr.indexOf("cli-eval-errors-files/0.em:3:26, <js>:6:9)") > 0
ok stderr.indexOf("cli-eval-errors-files/1.em:4:6, <js>:7:9)") > 0
ok stderr.indexOf("cli-eval-errors-files/1.em <js>:7:9)") > 0

done()

Expand Down

0 comments on commit 2134700

Please sign in to comment.