Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104941562
compileCode.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Mar 13, 13:24
Size
1 KB
Mime Type
text/x-java
Expires
Sat, Mar 15, 13:24 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
24882443
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
compileCode.js
View Options
import "core-js/modules/es.regexp.exec";
import "core-js/modules/es.string.match";
import "core-js/modules/es.string.trim";
import { transform } from 'buble';
import transpileImports from './transpileImports';
var compile = function compile(code, config) {
return transform(code, config).code;
};
var startsWithJsx = function startsWithJsx(code) {
return !!code.trim().match(/^</);
};
var wrapCodeInFragment = function wrapCodeInFragment(code) {
return "<React.Fragment>" + code + "</React.Fragment>;";
};
/*
* 1. Wrap code in React Fragment if it starts with JSX element
* 2. Transform import statements into require() calls
* 3. Compile code using Buble
*/
export default function compileCode(code, compilerConfig, onError) {
try {
var wrappedCode = startsWithJsx(code) ? wrapCodeInFragment(code) : code;
var compiledCode = compile(wrappedCode, compilerConfig);
return transpileImports(compiledCode);
} catch (err) {
if (onError && err instanceof Error) {
onError(err);
}
}
return '';
}
Event Timeline
Log In to Comment