How to use lebab - 5 common examples

To help you get started, we’ve selected a few lebab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github realywithoutname / mini-program-webpack-loader / src / ali / transxml.js View on Github external
generics.push(value)
        }
      }

      assets[distJsonPath] = new ConcatSource(JSON.stringify(jsonFileContent))
      assets[distWxmlPath] = updateWxmlGeneric(genericMap, wxmlFileContent)
    }
  }

  for (const file of tree.wxs) {
    let distPath = toTargetPath(
      utils.getDistPath(file)
    )
    let code = getAssetContent(file, compilation)
    let result = transform(code, ['commonjs'])

    // console.log(result.code, distPath)
    assets[distPath] = new ConcatSource(result.code)
  }
  // TODO 删除 template
  // Object.keys(assets).forEach(path => {
  //   if (rootXmlEntrys.indexOf(path) === -1 && /\.axml$/.test(path)) {
  //     // delete assets[path]
  //   }
  // })

  /**
   * 外部传入的事件只支持 onXXX,catch 要处理
   */
  let events = []
  for (let eventName of eventSet) {
github jeremyrajan / vscode-exts / extensions / vscode-lebab / src / extension.ts View on Github external
const es5_es6 = vscode.commands.registerCommand('extension.lebab', () => {
    const editor = vscode.window.activeTextEditor;
    const fileName = vscode.window.activeTextEditor.document.fileName;
    if (!editor) {
       return; // No open text editor
    }

    const textCode = editor.document.getText();
    // check for errors in JS code and if yes, then show the error.
    try {
      parse(textCode)
    } catch(err) {
      return vscode.window.showErrorMessage(`ERROR: ${err.description} at ${err.lineNumber}`);
    }
    // transforms: https://github.com/lebab/lebab#safe-transforms
    const {code, warnings}: {code: string, warnings: IWarnings} = transform(textCode, ['arrow', 'let', 'for-of', 'for-each', 'arg-rest', 'arg-spread', 'obj-method', 'obj-shorthand', 'no-strict', 'exponent', 'template']);

    const es6File = vscode.window.activeTextEditor.document.uri.fsPath.replace(/[.*]/, '_es6.');
    const setting: vscode.Uri = vscode.Uri.parse('untitled:' + es6File);
    vscode.workspace.openTextDocument(setting).then((a: vscode.TextDocument) => {
      vscode.window.showTextDocument(a, 1, false)
      .then(e => {
        e.edit(edit => {
          /**
           * If its an untitled file, then we will insert the ES6 after 2 line breaks in same file.
           */
          if (es6File.includes('Untitled')) {
            edit.insert(new vscode.Position(0, 0), `\n \n ${code}`);
          } else {
            // Otherwise create a new file with `name_es6.js` and paste the code.
            edit.insert(new vscode.Position(0, 0), code);
          }
github guigrpa / storyboard / sandbox / cjsxToEs6.js View on Github external
promise = promise.then(() => {
    console.log(`Processing ${filePath}...`);
    const { dir, name } = path.parse(filePath);
    const outPath = path.join(dir, `${name}.js`);
    const cjsxCode = fs.readFileSync(filePath, 'utf8');
    let code = cjsx.compile(cjsxCode, {
      header: false,
      bare: true,
    });
    const tmp = lebab.transform(code, [
      'arrow',
      'commonjs',
      'obj-shorthand',
      'for-each',
      'multi-var',
    ]);
    code = tmp.code;
    if (tmp.warnings.length) console.log(tmp.warnings);
    code = babel.transform(code, {
      plugins: ['transform-react-createelement-to-jsx'],
    }).code;
    fs.writeFileSync(outPath, `${code}\n`, 'utf8');
  });
});
github v8 / web-tooling-benchmark / src / lebab-benchmark.js View on Github external
return payloads.map(({ payload, options }) =>
      lebab.transform(payload, options)
    );
github kvz / invig / src / Invig.js View on Github external
async transform (srcPath, args) {
    try {
      srcPath = srcPath.replace(/\.coffee$/, '.js')
      const sourceCode = await fs.readFile(srcPath, 'utf8')
      const { code } = lebab.transform(sourceCode, args)
      if (!this.opts.dryrun) {
        await fs.outputFile(srcPath, code)
      }
    } catch (err) {
      throw err
    }
  }

lebab

Turn your ES5 code into readable ES6/ES7

MIT
Latest version published 4 months ago

Package Health Score

71 / 100
Full package analysis

Popular lebab functions