Skip to content

Commit 1b57341

Browse files
committed
cleaning up the previous merge -- moving it out to helpers.invertLiterate
1 parent 51b1aff commit 1b57341

File tree

6 files changed

+42
-43
lines changed

6 files changed

+42
-43
lines changed

lib/coffee-script/command.js

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/helpers.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffee-script/lexer.js

Lines changed: 3 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/command.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ path = require 'path'
1010
helpers = require './helpers'
1111
optparse = require './optparse'
1212
CoffeeScript = require './coffee-script'
13-
{rewriteLiterate} = require './lexer'
1413
{spawn, exec} = require 'child_process'
1514
{EventEmitter} = require 'events'
1615

@@ -123,7 +122,8 @@ compileScript = (file, input, base) ->
123122
else if o.nodes then printLine CoffeeScript.nodes(t.input, t.options).toString().trim()
124123
else if o.run then CoffeeScript.run t.input, t.options
125124
else if o.join and t.file isnt o.join
126-
sourceCode[sources.indexOf(t.file)] = if helpers.isLiterate file then rewriteLiterate t.input else t.input
125+
t.input = helpers.invertLiterate t.input if helpers.isLiterate file
126+
sourceCode[sources.indexOf(t.file)] = t.input
127127
compileJoin()
128128
else
129129
compiled = CoffeeScript.compile t.input, t.options

src/helpers.coffee

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ exports.some = Array::some ? (fn) ->
6060
return true for e in this when fn e
6161
false
6262

63+
# Simple function for inverting Literate CoffeeScript code by putting the
64+
# documentation in comments, and bumping the actual code back out to the edge ...
65+
# producing a string of CoffeeScript code that can be compiled "normally".
66+
exports.invertLiterate = (code) ->
67+
lines = for line in code.split('\n')
68+
if match = (/^([ ]{4}|\t)/).exec line
69+
line[match[0].length..]
70+
else
71+
'# ' + line
72+
lines.join '\n'
73+
6374
# Merge two jison-style location data objects together.
6475
# If `last` is not provided, this will simply return `first`.
6576
buildLocationData = (first, last) ->

src/lexer.coffee

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@
1212
{Rewriter, INVERSES} = require './rewriter'
1313

1414
# Import the helpers we need.
15-
{count, starts, compact, last, locationDataToString} = require './helpers'
16-
17-
# Rewrite literate CoffeeScript code, converting Markdown text into inline comments.
18-
exports.rewriteLiterate = rewriteLiterate = (code) ->
19-
lines = for line in code.split('\n')
20-
if match = LITERATE.exec line
21-
line[match[0].length..]
22-
else
23-
'# ' + line
24-
lines.join '\n'
15+
{count, starts, compact, last, invertLiterate, locationDataToString} = require './helpers'
2516

2617
# The Lexer Class
2718
# ---------------
@@ -93,7 +84,7 @@ exports.Lexer = class Lexer
9384
if WHITESPACE.test code
9485
code = "\n#{code}"
9586
@chunkLine--
96-
code = rewriteLiterate code if @literate
87+
code = invertLiterate code if @literate
9788
code
9889

9990
# Tokenizers
@@ -782,8 +773,6 @@ WHITESPACE = /^[^\n\S]+/
782773

783774
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)$)|^(?:\s*#(?!##[^#]).*)+/
784775

785-
LITERATE = /^([ ]{4}|\t)/
786-
787776
CODE = /^[-=]>/
788777

789778
MULTI_DENT = /^(?:\n[^\n\S]*)+/

0 commit comments

Comments
 (0)