A curated list of browser globals that commonly cause confusion and are not recommended to use without an explicit window qualifier
Overall
score
97%
Build a simple JavaScript transpilation tool that transforms modern JavaScript features into browser-compatible code.
Create a utility that takes modern JavaScript/JSX code as input and outputs transpiled code compatible with older browsers. Your tool should leverage a Babel preset to handle the transformation.
Your tool must implement a transpile function that:
Your transpiler must handle:
@generates
/**
* Transpiles modern JavaScript/JSX code to ES5-compatible code
* @param {string} code - The modern JavaScript/JSX code to transpile
* @param {Object} options - Optional configuration
* @param {boolean} options.jsx - Whether to transform JSX (default: true)
* @returns {string} The transpiled JavaScript code
* @throws {Error} If the code contains syntax errors
*/
function transpile(code, options = {}) {
// Implementation
}
module.exports = { transpile };const input = '<div>Hello World</div>';
const output = transpile(input);
// Output should not contain JSX syntax
// Output should be valid JavaScriptconst input = 'const add = (a, b) => a + b;';
const output = transpile(input);
// Output should not use arrow function syntaxconst input = 'async function fetchData() { await fetch("/api"); }';
const output = transpile(input);
// Output should be compatible with older browsersconst invalidCode = 'const x = ;';
// Should throw an error with a descriptive messageProvides JavaScript and JSX transformation capabilities with preset configurations for modern JavaScript features, React JSX, and TypeScript support.
Install with Tessl CLI
npx tessl i tessl/npm-confusing-browser-globalsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10