Skip to content

Commit

Permalink
Remove unecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Oct 10, 2023
1 parent ad7d432 commit 1405720
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions test/specs/optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ var fs = require('fs'),
TU = require('../lib/testUtils'),
CONST = require('../../Alloy/common/constants'),
_ = require('lodash'),
sourceMapper = require('../../Alloy/commands/compile/sourceMapper'),
babylon = require('@babel/parser'),
babel = require('@babel/core'),
swc = require('@swc/core'),
Optimizer = require('../../Alloy/commands/compile/ast/optimizer-plugin');

Expand Down Expand Up @@ -45,7 +42,7 @@ var tests = [
['var a = true ? 1 : 0;', 'var a = true ? 1 : 0;'],
['var num = isNaN(amount) || amount === "" || amount === null ? 0.00 : amount;', 'var num = isNaN(amount) || amount === "" || amount === null ? 0.00 : amount;'],

// // TODO: Revisit all "var a,a=2;" expecteds once ALOY-540 is resolved
// TODO: Revisit all "var a,a=2;" expecteds once ALOY-540 is resolved

// // make sure we didn't break normal if conditions
['if (true) {\n var a = 1;\n} else {\n var a = 2;\n}', "if (true) {\n var a = 1;\n} else {\n var a = 2;\n}"],
Expand All @@ -64,7 +61,7 @@ var tests = [
["var platform = (Ti.Platform.name === '<%= name %>') ? 1 : 0", "var platform = (\"<%= name %>\" === \"<%= name %>\") ? 1 : 0;"],
["var platform = (Ti.Platform.name === '<%= name %>') ? true : false", "var platform = (\"<%= name %>\" === \"<%= name %>\") ? true : false;"],

// // check identities
// check identities
["var a = Ti.Platform.name === Titanium.Platform.name","var a = \"<%= name %>\" === \"<%= name %>\";"],

// // shouldn't attempt to process anything other than strings
Expand All @@ -78,7 +75,7 @@ var tests = [
["if ('<%= name %>' === Ti.Platform.name) var a = 1; else var a = 2;", "if (\"<%= name %>\" === \"<%= name %>\") var a = 1;\nelse var a = 2;"],
["if ('<%= name %>' !== Ti.Platform.name) var a = 1; else var a = 2;", "if (\"<%= name %>\" !== \"<%= name %>\") var a = 1;\nelse var a = 2;"],

// // works if Ti.Platform.* is on the left or right hand side
// works if Ti.Platform.* is on the left or right hand side
["if ('<%= name %>' === Ti.Platform.name) {\n var a = 1;\n} else {\n a = 2;\n}", "if (\"<%= name %>\" === \"<%= name %>\") {\n var a = 1;\n} else {\n a = 2;\n}"],

['var a = OS_IOS', 'var a = true;', ['ios']],
Expand Down Expand Up @@ -107,27 +104,7 @@ describe('optimizer.js', function() {
expect(true).toBe(true);
});

it(prefix + 'parses AST with babylon', function() {
var parseFunction = function() {
ast = babylon.parse(testContent);
};
expect(parseFunction).not.toThrow();
});

it(prefix + 'optimizes code via Babel and our custom plugins', function() {
// execute the squeeze to remove dead code, always performed
// as the last step of JS file processing. The unit testing here
// uses the same settings as the Alloy compile process.
// var squeezeFunction = function() {
// var options = _.extend(_.clone(sourceMapper.OPTIONS_OUTPUT), {
// plugins: [['./Alloy/commands/compile/ast/optimizer-plugin', {platform: platform}]]
// });
// var result = babel.transformFromAstSync(ast, null, options);
// ast = result.ast;
// code = result.code.replace(/\s*$/,'');
// };
// expect(squeezeFunction).not.toThrow();

function optimize() {
const x = swc.parseSync(testContent);

Expand All @@ -142,8 +119,6 @@ describe('optimizer.js', function() {
it(prefix + 'generated code matches expected code', function() {
var passFor = test[2];
var expected = _.template(test[1])(platforms[platform]);
console.log(code);
console.log(expected);
if (!passFor || _.includes(passFor, platform)) {
expect(code).toBe(expected);
} else {
Expand All @@ -156,11 +131,6 @@ describe('optimizer.js', function() {
});
});

// helper functions
function notPlatform(platform) {
return _.reject(CONST.PLATFORMS, function(p) { return p === platform; } );
}

function pad(string) {
var ret = '';
for (var i = 0; i < 10 - string.length; i++) {
Expand Down

0 comments on commit 1405720

Please sign in to comment.