@@ -311,8 +311,7 @@ module.exports = {
311311 } )
312312 } ,
313313
314- add ( filePath , snippetsBySelector , isDisabled ) {
315- if ( isDisabled == null ) { isDisabled = false }
314+ add ( filePath , snippetsBySelector , isDisabled = false ) {
316315 for ( let selector in snippetsBySelector ) {
317316 const snippetsByName = snippetsBySelector [ selector ]
318317 const unparsedSnippetsByPrefix = { }
@@ -323,7 +322,7 @@ module.exports = {
323322 attributes . id = this . snippetIdCounter ++
324323 if ( typeof body === 'string' ) {
325324 unparsedSnippetsByPrefix [ prefix ] = attributes
326- } else if ( ( body == null ) ) {
325+ } else if ( body == null ) {
327326 unparsedSnippetsByPrefix [ prefix ] = null
328327 }
329328 }
@@ -333,32 +332,29 @@ module.exports = {
333332 } ,
334333
335334 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+ }
344339 } ,
345340
346341 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+
349347 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 ( ' ' )
353350 } ,
354351
355- storeUnparsedSnippets ( value , path , selector , isDisabled ) {
352+ storeUnparsedSnippets ( value , path , selector , isDisabled = false ) {
356353 // The `isDisabled` flag determines which scoped property store we'll use.
357354 // Active snippets get put into one and inactive snippets get put into
358355 // another. Only the first one gets consulted when we look up a snippet
359356 // prefix for expansion, but both stores have their contents exported when
360357 // the settings view asks for all available snippets.
361- if ( isDisabled == null ) { isDisabled = false }
362358 const unparsedSnippets = { }
363359 unparsedSnippets [ selector ] = { "snippets" : value }
364360 const store = isDisabled ? this . disabledSnippetsScopedPropertyStore : this . scopedPropertyStore
@@ -378,14 +374,20 @@ module.exports = {
378374 } ,
379375
380376 parsedSnippetsForScopes ( scopeDescriptor ) {
381- let attributes , prefix , unparsedLegacySnippetsByPrefix
377+ let attributes
378+ let prefix
379+ let unparsedLegacySnippetsByPrefix
380+
382381 const unparsedSnippetsByPrefix = this . scopedPropertyStore . getPropertyValue (
383382 this . getScopeChain ( scopeDescriptor ) ,
384383 "snippets"
385384 )
386385
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 ) {
389391 unparsedLegacySnippetsByPrefix = this . scopedPropertyStore . getPropertyValue (
390392 this . getScopeChain ( legacyScopeDescriptor ) ,
391393 "snippets"
@@ -394,18 +396,18 @@ module.exports = {
394396
395397 const snippets = { }
396398
397- if ( unparsedSnippetsByPrefix != null ) {
399+ if ( unparsedSnippetsByPrefix ) {
398400 for ( prefix in unparsedSnippetsByPrefix ) {
399401 attributes = unparsedSnippetsByPrefix [ prefix ]
400402 if ( typeof ( attributes != null ? attributes . body : undefined ) !== 'string' ) { continue }
401403 snippets [ prefix ] = this . getParsedSnippet ( attributes )
402404 }
403405 }
404406
405- if ( unparsedLegacySnippetsByPrefix != null ) {
407+ if ( unparsedLegacySnippetsByPrefix ) {
406408 for ( prefix in unparsedLegacySnippetsByPrefix ) {
407409 attributes = unparsedLegacySnippetsByPrefix [ prefix ]
408- if ( snippets [ prefix ] != null ) { continue }
410+ if ( snippets [ prefix ] ) { continue }
409411 if ( typeof ( attributes != null ? attributes . body : undefined ) !== 'string' ) { continue }
410412 snippets [ prefix ] = this . getParsedSnippet ( attributes )
411413 }
@@ -447,9 +449,11 @@ module.exports = {
447449 // Returns `null` if the values aren't the same for all cursors
448450 getPrefixText ( snippets , editor ) {
449451 const wordRegex = this . wordRegexForSnippets ( snippets )
450- let [ snippetPrefix , wordPrefix ] = Array . from ( [ ] )
451452
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 ( ) ) {
453457 const position = cursor . getBufferPosition ( )
454458
455459 const prefixStart = cursor . getBeginningOfCurrentWordBufferPosition ( { wordRegex} )
@@ -471,7 +475,7 @@ module.exports = {
471475 const prefixes = { }
472476
473477 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 }
475479 }
476480
477481 const prefixCharacters = Object . keys ( prefixes ) . join ( '' )
@@ -500,33 +504,29 @@ module.exports = {
500504 } ,
501505
502506 snippetToExpandUnderCursor ( editor ) {
503- let prefixData
504507 if ( ! editor . getLastSelection ( ) . isEmpty ( ) ) { return false }
505508 const snippets = this . getSnippets ( editor )
506509 if ( _ . isEmpty ( snippets ) ) { return false }
507510
508- if ( prefixData = this . getPrefixText ( snippets , editor ) ) {
511+ let prefixData = this . getPrefixText ( snippets , editor )
512+ if ( prefixData ) {
509513 return this . snippetForPrefix ( snippets , prefixData . snippetPrefix , prefixData . wordPrefix )
510514 }
511515 } ,
512516
513517 expandSnippetsUnderCursors ( editor ) {
514- let snippet
515- if ( ! ( snippet = this . snippetToExpandUnderCursor ( editor ) ) ) { return false }
518+ let snippet = this . snippetToExpandUnderCursor ( editor )
519+ if ( ! snippet ) { return false }
516520
517521 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 ) }
524524 } )
525525
526526 this . findOrCreateMarkerLayer ( editor )
527527 editor . transact ( ( ) => {
528528 const cursors = editor . getCursors ( )
529- for ( let cursor of Array . from ( cursors ) ) {
529+ for ( let cursor of cursors ) {
530530 const cursorPosition = cursor . getBufferPosition ( )
531531 const startPoint = cursorPosition . translate ( [ 0 , - snippet . prefix . length ] , [ 0 , 0 ] )
532532 cursor . selection . setBufferRange ( [ startPoint , cursorPosition ] )
@@ -538,7 +538,7 @@ module.exports = {
538538
539539 goToNextTabStop ( editor ) {
540540 let nextTabStopVisited = false
541- for ( let expansion of Array . from ( this . getExpansions ( editor ) ) ) {
541+ for ( let expansion of this . getExpansions ( editor ) ) {
542542 if ( expansion != null ? expansion . goToNextTabStop ( ) : undefined ) {
543543 nextTabStopVisited = true
544544 }
@@ -548,7 +548,7 @@ module.exports = {
548548
549549 goToPreviousTabStop ( editor ) {
550550 let previousTabStopVisited = false
551- for ( let expansion of Array . from ( this . getExpansions ( editor ) ) ) {
551+ for ( let expansion of this . getExpansions ( editor ) ) {
552552 if ( expansion != null ? expansion . goToPreviousTabStop ( ) : undefined ) {
553553 previousTabStopVisited = true
554554 }
@@ -560,13 +560,13 @@ module.exports = {
560560 return EditorStore . findOrCreate ( editor )
561561 } ,
562562
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+ // },
566566
567567 findOrCreateMarkerLayer ( editor ) {
568568 let layer = this . editorMarkerLayers . get ( editor )
569- if ( layer == null ) {
569+ if ( layer === undefined ) {
570570 layer = editor . addMarkerLayer ( { maintainHistory : true } )
571571 this . editorMarkerLayers . set ( editor , layer )
572572 }
@@ -583,11 +583,11 @@ module.exports = {
583583 // There are no more active instances of this expansion, so we should undo
584584 // the spying we set up on this editor.
585585 store . stopObserving ( )
586- return store . stopObservingHistory ( )
586+ store . stopObservingHistory ( )
587587 } ,
588588
589589 addExpansion ( editor , snippetExpansion ) {
590- return this . getStore ( editor ) . addExpansion ( snippetExpansion )
590+ this . getStore ( editor ) . addExpansion ( snippetExpansion )
591591 } ,
592592
593593 textChanged ( editor , event ) {
@@ -598,36 +598,34 @@ module.exports = {
598598
599599 this . ignoringTextChangesForEditor ( editor , ( ) =>
600600 editor . transact ( ( ) =>
601- Array . from ( activeExpansions ) . map ( ( expansion ) =>
601+ activeExpansions . map ( expansion =>
602602 expansion . textChanged ( event ) )
603603 )
604604 )
605605
606606 // Create a checkpoint here to consolidate all the changes we just made into
607607 // the transaction that prompted them.
608- return this . makeCheckpoint ( editor )
608+ this . makeCheckpoint ( editor )
609609 } ,
610610
611611 // Perform an action inside the editor without triggering our `textChanged`
612612 // callback.
613613 ignoringTextChangesForEditor ( editor , callback ) {
614614 this . stopObservingEditor ( editor )
615615 callback ( )
616- return this . observeEditor ( editor )
616+ this . observeEditor ( editor )
617617 } ,
618618
619619 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 ) )
623621 } ,
624622
625623 stopObservingEditor ( editor ) {
626- return this . getStore ( editor ) . stopObserving ( )
624+ this . getStore ( editor ) . stopObserving ( )
627625 } ,
628626
629627 makeCheckpoint ( editor ) {
630- return this . getStore ( editor ) . makeCheckpoint ( )
628+ this . getStore ( editor ) . makeCheckpoint ( )
631629 } ,
632630
633631 insert ( snippet , editor , cursor ) {
@@ -642,22 +640,18 @@ module.exports = {
642640
643641 getUnparsedSnippets ( ) {
644642 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+ }
661655
662656 iterate ( this . scopedPropertyStore . propertySets )
663657 iterate ( this . disabledSnippetsScopedPropertyStore . propertySets )
@@ -676,15 +670,6 @@ module.exports = {
676670
677671 onUndoOrRedo ( editor , isUndo ) {
678672 const activeExpansions = this . getExpansions ( editor )
679- return Array . from ( activeExpansions ) . map ( ( expansion ) =>
680- expansion . onUndoOrRedo ( isUndo ) )
673+ activeExpansions . forEach ( expansion => expansion . onUndoOrRedo ( isUndo ) )
681674 }
682675}
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