-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: [TIMOB-26403] Add plugin to convert all top level declarations t…
…o global scope (#47) * [TIMOB-26403] Add plugin to convert all top level declarations to global scope * [TIMOB-26403] Use cli logger instance only if provided * 0.6.4 * Fix assertion in adb tests
- Loading branch information
1 parent
2d746a8
commit 00b5334
Showing
9 changed files
with
161 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
const _path = require('path'); | ||
/** | ||
* Convert all top level variable declarations in "app.js" into explictly | ||
* defined variables on the global scope. | ||
*/ | ||
module.exports = function (babel) { | ||
const t = babel.types; | ||
let didEdits = false; | ||
return { | ||
name: 'app.js top level variables global transform', | ||
visitor: { | ||
Program: function (path, state) { | ||
const logger = state.opts.logger; | ||
if (_path.basename(this.file.opts.filename) !== 'app.js') { | ||
return; | ||
} | ||
for (const bodyPath of path.get('body')) { | ||
for (const name in t.getBindingIdentifiers(bodyPath.node, false, true)) { | ||
didEdits = true; | ||
bodyPath.insertAfter( | ||
t.expressionStatement( | ||
t.assignmentExpression( | ||
'=', | ||
t.identifier(`global.${name} `), | ||
t.identifier(`${name}`) | ||
) | ||
) | ||
); | ||
} | ||
} | ||
if (didEdits) { | ||
logger && logger.warn('The implicit global scope for variable declarations in app.js is deprecated in 7.5.0, and will be removed in 9.0.0'); | ||
} | ||
} | ||
} | ||
}; | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const path = require('path'); | ||
const pluginTester = require('babel-plugin-tester'); | ||
const plugin = require('../lib/babel-plugins/global-scope'); | ||
|
||
pluginTester({ | ||
plugin, | ||
tests: { | ||
'exposes declerations as global variables': { | ||
babelOptions: { | ||
filename: 'app.js' | ||
}, | ||
fixture: path.join(__dirname, 'resources', 'global-plugin', 'app.js'), | ||
outputFixture: path.join(__dirname, 'resources', 'global-plugin', 'output.js'), | ||
}, | ||
'should only operate on app.js': { | ||
babelOptions: { | ||
filename: 'another-file.js' | ||
}, | ||
fixture: path.join(__dirname, 'resources', 'global-plugin', 'app.js'), | ||
outputFixture: path.join(__dirname, 'resources', 'global-plugin', 'app.js'), | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function foobar() { | ||
var x = 'bar'; | ||
} | ||
global.aGlobalVar = 'foobar'; | ||
const foo = () => {}; | ||
let win = Ti.UI.createWindow({ | ||
backgroundColor: 'white' | ||
}); | ||
var textField = Ti.UI.createTextField({ | ||
borderStyle: Ti.UI.INPUT_BORDERSTYLE_BEZEL, | ||
color: '#336699', | ||
top: 10, left: 10, | ||
width: 250, height: 60 | ||
}); | ||
win.add(textField); | ||
win.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function foobar() { | ||
var x = 'bar'; | ||
} | ||
global.foobar = foobar; | ||
global.aGlobalVar = 'foobar'; | ||
const foo = () => {}; | ||
global.foo = foo; | ||
let win = Ti.UI.createWindow({ | ||
backgroundColor: 'white' | ||
}); | ||
global.win = win; | ||
var textField = Ti.UI.createTextField({ | ||
borderStyle: Ti.UI.INPUT_BORDERSTYLE_BEZEL, | ||
color: '#336699', | ||
top: 10, left: 10, | ||
width: 250, height: 60 | ||
}); | ||
global.textField = textField; | ||
win.add(textField); | ||
win.open(); |