mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Don’t allow mixing different types of whitespace for indentation, per line.
This commit is contained in:
parent
98068611b1
commit
bb40b1188c
4 changed files with 32 additions and 37 deletions
|
@ -349,6 +349,10 @@ exports.Lexer = class Lexer
|
|||
noNewlines = @unfinished()
|
||||
|
||||
newIndentLiteral = if size > 0 then indent[-size..] else ''
|
||||
unless /^(.?)\1*$/.exec newIndentLiteral
|
||||
@error 'mixed indentation', offset: indent.length
|
||||
return indent.length
|
||||
|
||||
minLiteralLength = Math.min newIndentLiteral.length, @indentLiteral.length
|
||||
if newIndentLiteral[...minLiteralLength] isnt @indentLiteral[...minLiteralLength]
|
||||
@error 'indentation mismatch', offset: indent.length
|
||||
|
|
|
@ -41,18 +41,6 @@ test "compiler error formatting", ->
|
|||
^^^^
|
||||
'''
|
||||
|
||||
test "compiler error formatting with mixed tab and space", ->
|
||||
assertErrorFormat """
|
||||
\t if a
|
||||
\t test
|
||||
""",
|
||||
'''
|
||||
[stdin]:1:4: error: unexpected if
|
||||
\t if a
|
||||
\t ^^
|
||||
'''
|
||||
|
||||
|
||||
if require?
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
|
|
|
@ -266,21 +266,24 @@ test "don’t allow mixing of spaces and tabs for indentation", ->
|
|||
catch e
|
||||
eq 'indentation mismatch', e.message
|
||||
|
||||
test "indentation can be a mix of spaces and tabs, if each line is the same", ->
|
||||
test "each code block that starts at indentation 0 can use a different style", ->
|
||||
doesNotThrow ->
|
||||
CoffeeScript.compile '''
|
||||
new Layer
|
||||
x: 0
|
||||
y: 1
|
||||
new Layer
|
||||
x: 0
|
||||
y: 1
|
||||
'''
|
||||
|
||||
test "tabs and spaces cannot be mixed for indentation", ->
|
||||
try
|
||||
CoffeeScript.compile '''
|
||||
new Layer
|
||||
x: 0
|
||||
y: 1
|
||||
'''
|
||||
|
||||
test "each code block that starts at indentation 0 can use a different style", ->
|
||||
doesNotThrow ->
|
||||
CoffeeScript.compile '''
|
||||
new Layer
|
||||
x: 0
|
||||
y: 1
|
||||
new Layer
|
||||
x: 0
|
||||
y: 1
|
||||
'''
|
||||
ok no
|
||||
catch e
|
||||
eq 'mixed indentation', e.message
|
||||
|
|
|
@ -59,21 +59,21 @@ test "#1183: super + fat arrows", ->
|
|||
dolater = (cb) -> cb()
|
||||
|
||||
class A
|
||||
constructor: ->
|
||||
@_i = 0
|
||||
foo : (cb) ->
|
||||
dolater =>
|
||||
@_i += 1
|
||||
cb()
|
||||
constructor: ->
|
||||
@_i = 0
|
||||
foo : (cb) ->
|
||||
dolater =>
|
||||
@_i += 1
|
||||
cb()
|
||||
|
||||
class B extends A
|
||||
constructor : ->
|
||||
super
|
||||
foo : (cb) ->
|
||||
dolater =>
|
||||
dolater =>
|
||||
@_i += 2
|
||||
super cb
|
||||
constructor : ->
|
||||
super
|
||||
foo : (cb) ->
|
||||
dolater =>
|
||||
dolater =>
|
||||
@_i += 2
|
||||
super cb
|
||||
|
||||
b = new B
|
||||
b.foo => eq b._i, 3
|
||||
|
|
Loading…
Reference in a new issue