How to use the typescript.createStringLiteral function in typescript

To help you get started, we’ve selected a few typescript 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 xf00f / web3x / web3x-codegen / src / index.ts View on Github external
if (outputs.length === 0){
    return []
  } else if (outputs.length === 1) {
    // original return value.
    return [getTsTypeFromSolidityType(outputs[0], true)]
  } else {
    // multiple return values: return an object.
    const propSigs: PropertySignature[] = [];
    for (let index = 0; index < outputs.length; index++){
      const output = outputs[index];
      const type = getTsTypeFromSolidityType(output as AbiInput, true);
      if (output.name) {
        // name exists for the output: create a key for that
        const nameSig = ts.createPropertySignature(
          undefined,
          ts.createStringLiteral(output.name),
          undefined,
          type,
          undefined
        );
        propSigs.push(nameSig);
      }
      // always create a key for the index.
      const indexSig = ts.createPropertySignature(
        undefined,
        ts.createNumericLiteral(index.toString()),
        undefined,
        type,
        undefined
      );
      propSigs.push(indexSig);
    }
github AviVahl / ts-tools / packages / robotrix / src / react-dev-transformer.ts View on Github external
function addFileNameConst(
    sourceFile: ts.SourceFile,
    jsxFileNameIdentifier: ts.Identifier,
    fileName: string
): ts.SourceFile {
    const variableDecls = [
        ts.createVariableDeclaration(jsxFileNameIdentifier, undefined /* type */, ts.createStringLiteral(fileName))
    ];

    return insertStatementAfterImports(
        sourceFile,
        ts.createVariableStatement(
            undefined /* modifiers */,
            ts.createVariableDeclarationList(variableDecls, ts.NodeFlags.Const)
        )
    );
}
github ionic-team / stencil / src / compiler_next / transformers / add-static-style.ts View on Github external
const createStyleLiteral = (cmp: d.ComponentCompilerMeta, style: d.StyleCompiler) => {
  if (cmp.encapsulation === 'scoped') {
    // scope the css first
    const scopeId = getScopeId(cmp.tagName, style.modeName);
    return ts.createStringLiteral(
      scopeCss(style.styleStr, scopeId, false)
    );
  }

  return ts.createStringLiteral(style.styleStr);
};
github fuse-box / fuse-box / src / module-transformer / production.ts View on Github external
const visit: ts.Visitor = node => {
      if (webWorkers && ts.isNewExpression(node)) {
        const newText = node.expression.getText();
        if (newText === 'Worker' || newText === 'SharedWorker') {
          if (node.arguments.length === 1) {
            const firstArg = node.arguments[0];
            const statement = firstArg['text'];
            // map item
            const item = webWorkers.find(item => {
              return item.path === statement && item.type === newText;
            });
            if (item) {
              return ts.createNew(ts.createIdentifier(newText), undefined, [ts.createStringLiteral(item.bundlePath)]);
            }
          }
        }
      }
      if (isRequireCall(node)) {
        const text = node['arguments'][0].text;

        const target = pm.findDependantModule(text);
        if (!target) {
          if (config.target !== 'electron' && config.target !== 'server') {
            if (!props.flow.ctx.config.shoudIgnorePackage(text)) {
              // if (log.props.ignoreStatementErrors && log.props.ignoreStatementErrors.includes(text)) {
              //   return;
              // }
              log.error('Problem when resolving require "$text" in $file', {
                text: text,
github airtasker / spot / lib / src / generators / typescript / axios-client.ts View on Github external
([headerName, header]) =>
                            ts.createPropertyAssignment(
                              ts.createStringLiteral(header.headerFieldName),
                              ts.createIdentifier(headerName)
                            )
                        )
github airtasker / spot / lib / src / generators / typescript / validators.ts View on Github external
function booleanValidator(parameter: ts.Expression): ts.Expression {
  return ts.createStrictEquality(
    ts.createTypeOf(parameter),
    ts.createStringLiteral("boolean")
  );
}
github woutervh- / typescript-is / src / transform-module / visitor.ts View on Github external
function visitBooleanKeyword(node: ts.TypeNode, accessor: ts.Expression, visitorContext: VisitorContext) {
    return ts.createStrictEquality(ts.createTypeOf(accessor), ts.createStringLiteral('boolean'));
}
github Bearer / bearer-js / packages / transpiler / src / transformers / root-component-transformer.ts View on Github external
const decorators = node.decorators.map(decorator => {
          if (decoratorNamed(decorator, Decorators.RootComponent)) {
            const metadatum = metadata.components.find(component => component.classname === node.name.text)
            const shadowExp = getExpressionFromDecorator(decorator, 'shadow')
            const styleUrl = getExpressionFromDecorator(decorator, 'styleUrl')
            const options = [
              ts.createPropertyAssignment('tag', ts.createStringLiteral(metadatum.finalTagName)),
              ts.createPropertyAssignment('shadow', shadowExp || ts.createTrue())
            ]
            if (styleUrl) {
              options.push(ts.createPropertyAssignment('styleUrl', ts.createStringLiteral(styleUrl.text)))
            }

            return ts.updateDecorator(
              decorator,
              ts.createCall(ts.createIdentifier(Decorators.Component), undefined, [
                ts.createObjectLiteral(options, true)
              ])
            )
          }
          return decorator
        })
github woutervh- / typescript-is / src / transform-inline / visitor.ts View on Github external
function visitString(type: ts.Type, accessor: ts.Expression, visitorContext: VisitorContext) {
    if (visitorContext.mode.type === 'type-check') {
        return ts.createStrictEquality(ts.createTypeOf(accessor), ts.createStringLiteral('string'));
    } else {
        throw new Error('visitString should only be called during type-check mode.');
    }
}
github woutervh- / typescript-is / src / transform-module / visitor.ts View on Github external
function visitStringKeyword(node: ts.TypeNode, accessor: ts.Expression, visitorContext: VisitorContext) {
    return ts.createStrictEquality(ts.createTypeOf(accessor), ts.createStringLiteral('string'));
}