@@ -311,8 +311,7 @@ module.exports = {
311
311
} )
312
312
} ,
313
313
314
- add ( filePath , snippetsBySelector , isDisabled ) {
315
- if ( isDisabled == null ) { isDisabled = false }
314
+ add ( filePath , snippetsBySelector , isDisabled = false ) {
316
315
for ( let selector in snippetsBySelector ) {
317
316
const snippetsByName = snippetsBySelector [ selector ]
318
317
const unparsedSnippetsByPrefix = { }
@@ -323,7 +322,7 @@ module.exports = {
323
322
attributes . id = this . snippetIdCounter ++
324
323
if ( typeof body === 'string' ) {
325
324
unparsedSnippetsByPrefix [ prefix ] = attributes
326
- } else if ( ( body == null ) ) {
325
+ } else if ( body == null ) {
327
326
unparsedSnippetsByPrefix [ prefix ] = null
328
327
}
329
328
}
@@ -333,32 +332,29 @@ module.exports = {
333
332
} ,
334
333
335
334
addSnippetsInDisabledPackage ( bundle ) {
336
- return ( ( ) => {
337
- const result = [ ]
338
- for ( let filePath in bundle ) {
339
- const snippetsBySelector = bundle [ filePath ]
340
- result . push ( this . add ( filePath , snippetsBySelector , true ) )
341
- }
342
- return result
343
- } ) ( )
335
+ for ( let filePath in bundle ) {
336
+ const snippetsBySelector = bundle [ filePath ]
337
+ this . add ( filePath , snippetsBySelector , true )
338
+ }
344
339
} ,
345
340
346
341
getScopeChain ( object ) {
347
- let scopesArray = __guardMethod__ ( object , 'getScopesArray' , o => o . getScopesArray ( ) )
348
- if ( scopesArray == null ) { scopesArray = object }
342
+ let scopesArray = object
343
+ if ( object && object . getScopesArray ) {
344
+ scopesArray = object . getScopesArray ( )
345
+ }
346
+
349
347
return scopesArray
350
- . map ( function ( scope ) {
351
- if ( scope [ 0 ] !== '.' ) { scope = `.${ scope } ` }
352
- return scope } ) . join ( ' ' )
348
+ . map ( scope => scope [ 0 ] === '.' ? scope : `.${ scope } ` )
349
+ . join ( ' ' )
353
350
} ,
354
351
355
- storeUnparsedSnippets ( value , path , selector , isDisabled ) {
352
+ storeUnparsedSnippets ( value , path , selector , isDisabled = false ) {
356
353
// The `isDisabled` flag determines which scoped property store we'll use.
357
354
// Active snippets get put into one and inactive snippets get put into
358
355
// another. Only the first one gets consulted when we look up a snippet
359
356
// prefix for expansion, but both stores have their contents exported when
360
357
// the settings view asks for all available snippets.
361
- if ( isDisabled == null ) { isDisabled = false }
362
358
const unparsedSnippets = { }
363
359
unparsedSnippets [ selector ] = { "snippets" : value }
364
360
const store = isDisabled ? this . disabledSnippetsScopedPropertyStore : this . scopedPropertyStore
@@ -378,14 +374,20 @@ module.exports = {
378
374
} ,
379
375
380
376
parsedSnippetsForScopes ( scopeDescriptor ) {
381
- let attributes , prefix , unparsedLegacySnippetsByPrefix
377
+ let attributes
378
+ let prefix
379
+ let unparsedLegacySnippetsByPrefix
380
+
382
381
const unparsedSnippetsByPrefix = this . scopedPropertyStore . getPropertyValue (
383
382
this . getScopeChain ( scopeDescriptor ) ,
384
383
"snippets"
385
384
)
386
385
387
- const legacyScopeDescriptor = typeof atom . config . getLegacyScopeDescriptorForNewScopeDescriptor === 'function' ? atom . config . getLegacyScopeDescriptorForNewScopeDescriptor ( scopeDescriptor ) : undefined
388
- if ( legacyScopeDescriptor != null ) {
386
+ const legacyScopeDescriptor = atom . config . getLegacyScopeDescriptorForNewScopeDescriptor
387
+ ? atom . config . getLegacyScopeDescriptorForNewScopeDescriptor ( scopeDescriptor )
388
+ : undefined
389
+
390
+ if ( legacyScopeDescriptor ) {
389
391
unparsedLegacySnippetsByPrefix = this . scopedPropertyStore . getPropertyValue (
390
392
this . getScopeChain ( legacyScopeDescriptor ) ,
391
393
"snippets"
@@ -394,18 +396,18 @@ module.exports = {
394
396
395
397
const snippets = { }
396
398
397
- if ( unparsedSnippetsByPrefix != null ) {
399
+ if ( unparsedSnippetsByPrefix ) {
398
400
for ( prefix in unparsedSnippetsByPrefix ) {
399
401
attributes = unparsedSnippetsByPrefix [ prefix ]
400
402
if ( typeof ( attributes != null ? attributes . body : undefined ) !== 'string' ) { continue }
401
403
snippets [ prefix ] = this . getParsedSnippet ( attributes )
402
404
}
403
405
}
404
406
405
- if ( unparsedLegacySnippetsByPrefix != null ) {
407
+ if ( unparsedLegacySnippetsByPrefix ) {
406
408
for ( prefix in unparsedLegacySnippetsByPrefix ) {
407
409
attributes = unparsedLegacySnippetsByPrefix [ prefix ]
408
- if ( snippets [ prefix ] != null ) { continue }
410
+ if ( snippets [ prefix ] ) { continue }
409
411
if ( typeof ( attributes != null ? attributes . body : undefined ) !== 'string' ) { continue }
410
412
snippets [ prefix ] = this . getParsedSnippet ( attributes )
411
413
}
@@ -447,9 +449,11 @@ module.exports = {
447
449
// Returns `null` if the values aren't the same for all cursors
448
450
getPrefixText ( snippets , editor ) {
449
451
const wordRegex = this . wordRegexForSnippets ( snippets )
450
- let [ snippetPrefix , wordPrefix ] = Array . from ( [ ] )
451
452
452
- for ( let cursor of Array . from ( editor . getCursors ( ) ) ) {
453
+ let snippetPrefix = null
454
+ let wordPrefix = null
455
+
456
+ for ( let cursor of editor . getCursors ( ) ) {
453
457
const position = cursor . getBufferPosition ( )
454
458
455
459
const prefixStart = cursor . getBeginningOfCurrentWordBufferPosition ( { wordRegex} )
@@ -471,7 +475,7 @@ module.exports = {
471
475
const prefixes = { }
472
476
473
477
for ( let prefix in snippets ) {
474
- for ( let character of Array . from ( prefix ) ) { prefixes [ character ] = true }
478
+ for ( let character of prefix ) { prefixes [ character ] = true }
475
479
}
476
480
477
481
const prefixCharacters = Object . keys ( prefixes ) . join ( '' )
@@ -500,33 +504,29 @@ module.exports = {
500
504
} ,
501
505
502
506
snippetToExpandUnderCursor ( editor ) {
503
- let prefixData
504
507
if ( ! editor . getLastSelection ( ) . isEmpty ( ) ) { return false }
505
508
const snippets = this . getSnippets ( editor )
506
509
if ( _ . isEmpty ( snippets ) ) { return false }
507
510
508
- if ( prefixData = this . getPrefixText ( snippets , editor ) ) {
511
+ let prefixData = this . getPrefixText ( snippets , editor )
512
+ if ( prefixData ) {
509
513
return this . snippetForPrefix ( snippets , prefixData . snippetPrefix , prefixData . wordPrefix )
510
514
}
511
515
} ,
512
516
513
517
expandSnippetsUnderCursors ( editor ) {
514
- let snippet
515
- if ( ! ( snippet = this . snippetToExpandUnderCursor ( editor ) ) ) { return false }
518
+ let snippet = this . snippetToExpandUnderCursor ( editor )
519
+ if ( ! snippet ) { return false }
516
520
517
521
this . getStore ( editor ) . observeHistory ( {
518
- undo : event => {
519
- return this . onUndoOrRedo ( editor , event , true )
520
- } ,
521
- redo : event => {
522
- return this . onUndoOrRedo ( editor , event , false )
523
- }
522
+ undo : event => { this . onUndoOrRedo ( editor , event , true ) } ,
523
+ redo : event => { this . onUndoOrRedo ( editor , event , false ) }
524
524
} )
525
525
526
526
this . findOrCreateMarkerLayer ( editor )
527
527
editor . transact ( ( ) => {
528
528
const cursors = editor . getCursors ( )
529
- for ( let cursor of Array . from ( cursors ) ) {
529
+ for ( let cursor of cursors ) {
530
530
const cursorPosition = cursor . getBufferPosition ( )
531
531
const startPoint = cursorPosition . translate ( [ 0 , - snippet . prefix . length ] , [ 0 , 0 ] )
532
532
cursor . selection . setBufferRange ( [ startPoint , cursorPosition ] )
@@ -538,7 +538,7 @@ module.exports = {
538
538
539
539
goToNextTabStop ( editor ) {
540
540
let nextTabStopVisited = false
541
- for ( let expansion of Array . from ( this . getExpansions ( editor ) ) ) {
541
+ for ( let expansion of this . getExpansions ( editor ) ) {
542
542
if ( expansion != null ? expansion . goToNextTabStop ( ) : undefined ) {
543
543
nextTabStopVisited = true
544
544
}
@@ -548,7 +548,7 @@ module.exports = {
548
548
549
549
goToPreviousTabStop ( editor ) {
550
550
let previousTabStopVisited = false
551
- for ( let expansion of Array . from ( this . getExpansions ( editor ) ) ) {
551
+ for ( let expansion of this . getExpansions ( editor ) ) {
552
552
if ( expansion != null ? expansion . goToPreviousTabStop ( ) : undefined ) {
553
553
previousTabStopVisited = true
554
554
}
@@ -560,13 +560,13 @@ module.exports = {
560
560
return EditorStore . findOrCreate ( editor )
561
561
} ,
562
562
563
- createMarkerLayer ( editor ) {
564
- return this . editorMarkerLayers . set ( editor , editor . addMarkerLayer ( { maintainHistory : true } ) )
565
- } ,
563
+ // createMarkerLayer (editor) {
564
+ // this.editorMarkerLayers.set(editor, editor.addMarkerLayer({maintainHistory: true}))
565
+ // },
566
566
567
567
findOrCreateMarkerLayer ( editor ) {
568
568
let layer = this . editorMarkerLayers . get ( editor )
569
- if ( layer == null ) {
569
+ if ( layer === undefined ) {
570
570
layer = editor . addMarkerLayer ( { maintainHistory : true } )
571
571
this . editorMarkerLayers . set ( editor , layer )
572
572
}
@@ -583,11 +583,11 @@ module.exports = {
583
583
// There are no more active instances of this expansion, so we should undo
584
584
// the spying we set up on this editor.
585
585
store . stopObserving ( )
586
- return store . stopObservingHistory ( )
586
+ store . stopObservingHistory ( )
587
587
} ,
588
588
589
589
addExpansion ( editor , snippetExpansion ) {
590
- return this . getStore ( editor ) . addExpansion ( snippetExpansion )
590
+ this . getStore ( editor ) . addExpansion ( snippetExpansion )
591
591
} ,
592
592
593
593
textChanged ( editor , event ) {
@@ -598,36 +598,34 @@ module.exports = {
598
598
599
599
this . ignoringTextChangesForEditor ( editor , ( ) =>
600
600
editor . transact ( ( ) =>
601
- Array . from ( activeExpansions ) . map ( ( expansion ) =>
601
+ activeExpansions . map ( expansion =>
602
602
expansion . textChanged ( event ) )
603
603
)
604
604
)
605
605
606
606
// Create a checkpoint here to consolidate all the changes we just made into
607
607
// the transaction that prompted them.
608
- return this . makeCheckpoint ( editor )
608
+ this . makeCheckpoint ( editor )
609
609
} ,
610
610
611
611
// Perform an action inside the editor without triggering our `textChanged`
612
612
// callback.
613
613
ignoringTextChangesForEditor ( editor , callback ) {
614
614
this . stopObservingEditor ( editor )
615
615
callback ( )
616
- return this . observeEditor ( editor )
616
+ this . observeEditor ( editor )
617
617
} ,
618
618
619
619
observeEditor ( editor ) {
620
- return this . getStore ( editor ) . observe ( event => {
621
- return this . textChanged ( editor , event )
622
- } )
620
+ this . getStore ( editor ) . observe ( event => this . textChanged ( editor , event ) )
623
621
} ,
624
622
625
623
stopObservingEditor ( editor ) {
626
- return this . getStore ( editor ) . stopObserving ( )
624
+ this . getStore ( editor ) . stopObserving ( )
627
625
} ,
628
626
629
627
makeCheckpoint ( editor ) {
630
- return this . getStore ( editor ) . makeCheckpoint ( )
628
+ this . getStore ( editor ) . makeCheckpoint ( )
631
629
} ,
632
630
633
631
insert ( snippet , editor , cursor ) {
@@ -642,22 +640,18 @@ module.exports = {
642
640
643
641
getUnparsedSnippets ( ) {
644
642
const results = [ ]
645
- const iterate = sets =>
646
- ( ( ) => {
647
- const result = [ ]
648
- for ( let item of Array . from ( sets ) ) {
649
- const newItem = _ . deepClone ( item )
650
- // The atom-slick library has already parsed the `selector` property, so
651
- // it's an AST here instead of a string. The object has a `toString`
652
- // method that turns it back into a string. That custom behavior won't
653
- // be preserved in the deep clone of the object, so we have to handle it
654
- // separately.
655
- newItem . selectorString = item . selector . toString ( )
656
- result . push ( results . push ( newItem ) )
657
- }
658
- return result
659
- } ) ( )
660
-
643
+ const iterate = sets => {
644
+ for ( let item of sets ) {
645
+ const newItem = _ . deepClone ( item )
646
+ // The atom-slick library has already parsed the `selector` property, so
647
+ // it's an AST here instead of a string. The object has a `toString`
648
+ // method that turns it back into a string. That custom behavior won't
649
+ // be preserved in the deep clone of the object, so we have to handle it
650
+ // separately.
651
+ newItem . selectorString = item . selector . toString ( )
652
+ results . push ( newItem )
653
+ }
654
+ }
661
655
662
656
iterate ( this . scopedPropertyStore . propertySets )
663
657
iterate ( this . disabledSnippetsScopedPropertyStore . propertySets )
@@ -676,15 +670,6 @@ module.exports = {
676
670
677
671
onUndoOrRedo ( editor , isUndo ) {
678
672
const activeExpansions = this . getExpansions ( editor )
679
- return Array . from ( activeExpansions ) . map ( ( expansion ) =>
680
- expansion . onUndoOrRedo ( isUndo ) )
673
+ activeExpansions . forEach ( expansion => expansion . onUndoOrRedo ( isUndo ) )
681
674
}
682
675
}
683
-
684
- function __guardMethod__ ( obj , methodName , transform ) {
685
- if ( typeof obj !== 'undefined' && obj !== null && typeof obj [ methodName ] === 'function' ) {
686
- return transform ( obj , methodName )
687
- } else {
688
- return undefined
689
- }
690
- }
0 commit comments