Last active
June 24, 2019 21:25
-
-
Save hesyifei/eb293983260ecc9e77de48133181f2e9 to your computer and use it in GitHub Desktop.
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
var glob = require("glob"); | |
const ts = require("typescript"); | |
const { readFileSync, readdirSync, statSync } = require("fs"); | |
const { join } = require("path"); | |
const dirs = p => | |
readdirSync(p).filter(f => statSync(join(p, f)).isDirectory()); | |
var results = new Set(); | |
const alldirs = dirs("[FOLDER PATH HERE]/expo/packages/"); | |
alldirs.forEach(function(foldername) { | |
const folderpath = | |
"[FOLDER PATH HERE]/expo/packages/" + | |
foldername + | |
"/src/"; | |
glob(folderpath + "**/*.+(js|ts)", {}, function(er, files) { | |
files.forEach(function(filename) { | |
if (filename.includes("/node_modules/")) { | |
return; | |
} | |
if (filename.includes("/__tests__/")) { | |
return; | |
} | |
if (filename.endsWith(".web.ts") || filename.endsWith(".web.js")) { | |
return; | |
} | |
//console.log(filename); | |
const sourceFile = ts.createSourceFile( | |
filename, | |
readFileSync(filename).toString(), | |
ts.ScriptTarget.ES6, | |
false | |
); | |
//console.log(sourceFile); | |
let result = ts.transpileModule(sourceFile.text, { | |
compilerOptions: { | |
module: ts.ModuleKind.CommonJS | |
} | |
}); | |
//console.log(result.outputText); | |
//console.log(JSON.stringify(result)); | |
if (checkEsp(result.outputText)) { | |
console.warn(foldername); | |
results.add(foldername); | |
} | |
}); | |
}); | |
}); | |
function checkEsp(resulttext) { | |
var esprima = require("esprima"); | |
var espresult = esprima.parse(resulttext).body; | |
//console.log(espresult); | |
//console.log(JSON.stringify(espresult[3])); | |
var thisr = false; | |
espresult.forEach(function(value) { | |
if ( | |
(value.type === "ExpressionStatement" && | |
value.expression !== null && | |
value.expression.type !== null && | |
value.expression.type === "CallExpression" && | |
// Allows `export *` | |
value.expression.callee.name !== "__export" && | |
// Allows `export enum` and `export type` related things | |
!( | |
value.expression.callee.id === null && | |
( | |
( | |
((value.expression.arguments || [{}])[0].right || {}).left || | |
{} | |
).object || {} | |
).name === "exports" | |
) && | |
// Allows `Object.assign` | |
!( | |
(value.expression.callee.object || {}).name === "Object" && | |
(value.expression.callee.property || {}).name === "assign" | |
)) || | |
value.type === "IfStatement" | |
) { | |
//console.log("BOOO!"); | |
//console.log(value); | |
thisr = true; | |
} | |
}); | |
return thisr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment