@@ -99,6 +99,13 @@ const database = [
9999 newImport : `import * as libraryBlocks from 'blockly/blocks';` ,
100100 newRequire : `const libraryBlocks = require('blockly/blocks');` ,
101101 } ,
102+ {
103+ import : 'blockly' ,
104+ oldIdentifier : 'Blockly' ,
105+ newIdentifier : 'Blockly' , // no-op
106+ newImport : `import * as Blockly from 'blockly';` ,
107+ newRequire : `const Blockly = require('blockly');` , // no-op
108+ } ,
102109] ;
103110
104111/**
@@ -125,9 +132,18 @@ function migrateContents(contents) {
125132 */
126133function fixImport ( contents , migrationData ) {
127134 const identifier = getIdentifier ( contents , migrationData ) ;
135+ // Don't need to run if there are no references.
128136 if ( ! identifier ) return contents ;
129- const newContents = replaceReferences ( contents , migrationData , identifier ) ;
130- if ( newContents !== contents ) return addImport ( newContents , migrationData ) ;
137+ // If the identifier changed, update all references to it and the import
138+ if ( migrationData . oldIdentifier !== migrationData . newIdentifier ) {
139+ const newContents = replaceReferences ( contents , migrationData , identifier ) ;
140+ if ( newContents !== contents ) {
141+ return addImport ( newContents , migrationData ) ;
142+ }
143+ } else {
144+ // Just the import changed
145+ return addImport ( contents , migrationData ) ;
146+ }
131147 return contents ;
132148}
133149
0 commit comments