mirror of
https://github.com/atom/atom.git
synced 2026-02-15 00:55:14 -05:00
Use coffee-script node module
This required upgrading underscore which to fix issues with _.isEqual working across objects created from different documents. The upgrade required adding a custom _.isEqual extension that added back support for object's having an isEqual method that was removed in underscore 1.4.0.
This commit is contained in:
@@ -27,7 +27,7 @@ class SnippetExpansion
|
||||
return if @settingTabStop or bufferChanged
|
||||
oldTabStops = @tabStopsForBufferPosition(oldBufferPosition)
|
||||
newTabStops = @tabStopsForBufferPosition(newBufferPosition)
|
||||
@destroy() unless _.intersect(oldTabStops, newTabStops).length
|
||||
@destroy() unless _.intersection(oldTabStops, newTabStops).length
|
||||
|
||||
placeTabStopMarkers: (startPosition, tabStopRanges) ->
|
||||
@tabStopMarkers = tabStopRanges.map ({start, end}) =>
|
||||
|
||||
@@ -218,7 +218,7 @@ module.exports =
|
||||
readObject: (path) ->
|
||||
contents = @read(path)
|
||||
if @extension(path) is '.cson'
|
||||
{CoffeeScript} = require 'coffee-script'
|
||||
CoffeeScript = nodeRequire 'coffee-script'
|
||||
CoffeeScript.eval(contents, bare: true)
|
||||
else
|
||||
JSON.parse(contents)
|
||||
|
||||
@@ -61,7 +61,7 @@ exts =
|
||||
compiled = __read(cacheFilePath)
|
||||
writeToCache = false
|
||||
else
|
||||
{CoffeeScript} = require 'coffee-script'
|
||||
CoffeeScript = nodeRequire 'coffee-script'
|
||||
compiled = CoffeeScript.compile(__read(file), filename: file)
|
||||
writeToCache = true
|
||||
|
||||
@@ -76,7 +76,7 @@ getPath = (path) ->
|
||||
|
||||
cacheFilePath = getCacheFilePath(path)
|
||||
unless __exists(cacheFilePath)
|
||||
{CoffeeScript} = require 'coffee-script'
|
||||
CoffeeScript = nodeRequire 'coffee-script'
|
||||
compiled = CoffeeScript.compile(__read(path), filename: path)
|
||||
createCacheDirectory()
|
||||
fs.writeFileSync(cacheFilePath, compiled)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fs = require 'fs'
|
||||
{CoffeeScript} = require 'coffee-script'
|
||||
CoffeeScript = require 'coffee-script'
|
||||
|
||||
# Settings file looks like:
|
||||
# editor: # name of class
|
||||
|
||||
@@ -131,3 +131,53 @@ _.mixin
|
||||
for key, value of object
|
||||
newObject[key] = value if value?
|
||||
newObject
|
||||
|
||||
originalIsEqual = _.isEqual
|
||||
extendedIsEqual = (a, b, aStack=[], bStack=[]) ->
|
||||
return originalIsEqual(a, b) if a is b
|
||||
return originalIsEqual(a, b) if _.isFunction(a) or _.isFunction(b)
|
||||
return a.isEqual(b) if _.isFunction(a?.isEqual)
|
||||
return b.isEqual(a) if _.isFunction(b?.isEqual)
|
||||
|
||||
stackIndex = aStack.length
|
||||
while stackIndex--
|
||||
return bStack[stackIndex] is b if aStack[stackIndex] is a
|
||||
aStack.push(a)
|
||||
bStack.push(b)
|
||||
|
||||
equal = false
|
||||
if _.isArray(a) and _.isArray(b) and a.length is b.length
|
||||
equal = true
|
||||
for aElement, i in a
|
||||
unless extendedIsEqual(aElement, b[i], aStack, bStack)
|
||||
equal = false
|
||||
break
|
||||
else if _.isObject(a) and _.isObject(b)
|
||||
aCtor = a.constructor
|
||||
bCtor = b.constructor
|
||||
aCtorValid = _.isFunction(aCtor) and aCtor instanceof aCtor
|
||||
bCtorValid = _.isFunction(bCtor) and bCtor instanceof bCtor
|
||||
if aCtor isnt bCtor and not (aCtorValid and bCtorValid)
|
||||
equal = false
|
||||
else
|
||||
aKeyCount = 0
|
||||
equal = true
|
||||
for key, aValue of a
|
||||
continue unless _.has(a, key)
|
||||
aKeyCount++
|
||||
unless _.has(b, key) and extendedIsEqual(aValue, b[key], aStack, bStack)
|
||||
equal = false
|
||||
break
|
||||
if equal
|
||||
bKeyCount = 0
|
||||
for key, bValue of b
|
||||
bKeyCount++ if _.has(b, key)
|
||||
equal = aKeyCount is bKeyCount
|
||||
else
|
||||
equal = originalIsEqual(a, b)
|
||||
|
||||
aStack.pop()
|
||||
bStack.pop()
|
||||
equal
|
||||
|
||||
_.isEqual = (a, b) -> extendedIsEqual(a, b)
|
||||
|
||||
Reference in New Issue
Block a user