How to use the @babel/core.types.stringLiteral function in @babel/core

To help you get started, we’ve selected a few @babel/core 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 babel / babel / packages / babel-plugin-transform-member-expression-literals / src / index.js View on Github external
exit({ node }) {
          const prop = node.property;
          if (
            !node.computed &&
            t.isIdentifier(prop) &&
            !t.isValidES3Identifier(prop.name)
          ) {
            // foo.default -> foo["default"]
            node.property = t.stringLiteral(prop.name);
            node.computed = true;
          }
        },
      },
github r-murphy / babel-plugin-transform-modules-ui5 / packages / plugin / src / modules / visitor.js View on Github external
// e.g. import X, * as X2 from 'X'
          // Else it's probably combined with a default export. keep the tmpName and destructure it
          deconstructors.push(
            th.buildConstDeclaration({
              NAME: specifier.local,
              VALUE: t.identifier(imp.tmpName),
            })
          );
        }
      } else if (t.isImportSpecifier(specifier)) {
        // e.g. import { A } from 'X'
        deconstructors.push(
          th.buildNamedImportDestructor({
            MODULE: t.identifier(imp.tmpName),
            LOCAL: specifier.local,
            IMPORTED: t.stringLiteral(specifier.imported.name),
          })
        );
      } else {
        throw path.buildCodeFrameError(
          `Unknown ImportDeclaration specifier type ${specifier.type}`
        );
      }
    }

    path.replaceWithMultiple(deconstructors);

    if (deconstructors.length) {
      // Keep the same variable name if the same module is imported on another line.
      imp.locked = true;
    }
github babel / babel / packages / babel-plugin-transform-block-scoping / src / index.js View on Github external
return;
        }

        loopText = `${loopText}|${node.label.name}`;
      } else {
        // we shouldn't be transforming these statements because
        // they don't refer to the actual loop we're scopifying
        if (state.ignoreLabeless) return;

        // break statements mean something different in this context
        if (t.isBreakStatement(node) && state.inSwitchCase) return;
      }

      state.hasBreakContinue = true;
      state.map[loopText] = node;
      replace = t.stringLiteral(loopText);
    }

    if (path.isReturnStatement()) {
      state.hasReturn = true;
      replace = t.objectExpression([
        t.objectProperty(
          t.identifier("v"),
          node.argument || scope.buildUndefinedNode(),
        ),
      ]);
    }

    if (replace) {
      replace = t.returnStatement(replace);
      replace[this.LOOP_IGNORE] = true;
      path.skip();
github sokra / rawact / src / index.js View on Github external
ImportDeclaration(path) {
				if (!t.isStringLiteral(path.node.source)) return;
				const source = path.node.source.value;
				if (source !== "react" && source !== "react-dom") return;
				const newSpecifiers = [];
				for (const specifier of path.node.specifiers) {
					if (
						t.isImportDefaultSpecifier(specifier) ||
						t.isImportNamespaceSpecifier(specifier)
					) {
						this.reactNamespace.add(specifier.local.name);
						path.insertBefore(
							t.importDeclaration(
								[t.importNamespaceSpecifier(specifier.local)],
								t.stringLiteral("babel-plugin-rawact/lib/runtime/react")
							)
						);
					}
					if (t.isImportSpecifier(specifier)) {
						this.directImported.set(
							specifier.local.name,
							specifier.imported.name
						);
						newSpecifiers.push(
							t.importSpecifier(specifier.local, specifier.imported)
						);
					}
				}
				if (newSpecifiers.length > 0) {
					path.replaceWith(
						t.importDeclaration(
github babel / babel / packages / babel-helper-create-class-features-plugin / src / decorators.js View on Github external
function getKey(node) {
  if (node.computed) {
    return node.key;
  } else if (t.isIdentifier(node.key)) {
    return t.stringLiteral(node.key.name);
  } else {
    return t.stringLiteral(String(node.key.value));
  }
}
github sokra / rawact / src / nativeElementAttributes.js View on Github external
(old, local, store) =>
				t.expressionStatement(
					t.callExpression(scope.importHelper("replaceEventListener"), [
						scope.root(),
						node,
						t.stringLiteral(event),
						old,
						store(createListener(local))
					])
				),
			old =>
github babel / babel / packages / babel-plugin-transform-react-display-name / src / index.js View on Github external
function addDisplayName(id, call) {
    const props = call.arguments[0].properties;
    let safe = true;

    for (let i = 0; i < props.length; i++) {
      const prop = props[i];
      const key = t.toComputedKey(prop);
      if (t.isLiteral(key, { value: "displayName" })) {
        safe = false;
        break;
      }
    }

    if (safe) {
      props.unshift(
        t.objectProperty(t.identifier("displayName"), t.stringLiteral(id)),
      );
    }
  }
github expo / expo / packages / babel-plugin-universal-platforms / src / index.ts View on Github external
MemberExpression(p: NodePath) {
      if (!t.isAssignmentExpression(p.parent)) {
        if (p.matchesPattern('Platform.OS')) {
          p.replaceWith(t.stringLiteral(platform));
        } else if (p.matchesPattern('process.env.NODE_ENV')) {
          p.replaceWith(t.stringLiteral(mode));
        }
      }
    }
  };
github expo / expo / packages / babel-plugin-universal-platforms / src / index.ts View on Github external
MemberExpression(p: NodePath) {
      if (!t.isAssignmentExpression(p.parent)) {
        if (p.matchesPattern('Platform.OS')) {
          p.replaceWith(t.stringLiteral(platform));
        } else if (p.matchesPattern('process.env.NODE_ENV')) {
          p.replaceWith(t.stringLiteral(mode));
        }
      }
    }
  };