• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

TypeScript acorn.parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中acorn.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: readScript

export default function readScript(parser: Parser, start: number, attributes: Node[]) {
	const scriptStart = parser.index;
	const scriptEnd = parser.template.indexOf(scriptClosingTag, scriptStart);

	if (scriptEnd === -1) parser.error(`<script> must have a closing tag`);

	const source =
		repeat(' ', scriptStart) + parser.template.slice(scriptStart, scriptEnd);
	parser.index = scriptEnd + scriptClosingTag.length;

	let ast;

	try {
		ast = acorn.parse(source, {
			ecmaVersion: 9,
			sourceType: 'module',
			plugins: {
				dynamicImport: true
			}
		});
	} catch (err) {
		parser.acornError(err);
	}

	if (!ast.body.length) return null;

	ast.start = scriptStart;
	return {
		start,
		end: parser.index,
		attributes,
		content: ast,
	};
}
开发者ID:kristoferbaxter,项目名称:svelte,代码行数:34,代码来源:script.ts


示例2: acornParse

export const loadAndParseConformation = (
  fixtureFilePath: string
): ConformationTest[] => {
  const pathname = path.join(fixturesFolderPath, fixtureFilePath)
  const content = fs.readFileSync(pathname, 'utf8')
  const expectedValues: any[] = []
  const tests: ConformationTest[] = []

  acornParse(content, {
    ecmaVersion: 5,
    locations: true,
    onComment: (isBlock, text) => {
      if (!isBlock) {
        // tslint:disable-next-line
        expectedValues.push(eval(text.trim()))
      }
    }
  })

  const context = createContext({ week: 3 })
  const ast = parse(content, context).parser.program!

  for (const [idx, statement] of ast.body.entries()) {
    tests.push({
      statement: statement as es.Statement,
      expectedValue: expectedValues[idx]
    })
  }

  return tests
}
开发者ID:evansb,项目名称:source-toolchain,代码行数:31,代码来源:conformation.ts


示例3: processModule

function processModule(modulePath: string, context: IPaeckchenContext, detectedGlobals: IDetectedGlobals,
    plugins: any): ESTree.Program {
  // parse...
  const comments: any[] = [];
  const tokens: any[] = [];
  const moduleAst = parse(context.host.readFile(modulePath).toString(), {
    ecmaVersion: 7,
    sourceType: 'module',
    locations: true,
    ranges: true,
    allowHashBang: true,
    onComment: comments,
    onToken: tokens
  });
  // only attach comments which are not sourceMaps
  attachComments(moduleAst,
    comments.filter((comment: any) => comment.value.indexOf('# sourceMappingURL=') === -1), tokens);

  // ... check for global features...
  checkGlobals(detectedGlobals, moduleAst);

  // ... and rewrite ast
  Object.keys(plugins).forEach(plugin => {
    plugins[plugin](moduleAst, modulePath, context);
  });

  return moduleAst;
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:28,代码来源:modules.ts


示例4: it

 it('returns correct scope name if closure is passed as arguments', () => {
   const node: any = (parse('var x = function (n) {};').body[0] as any)
     .declarations[0].init
   const closure = new Closure(node, 0, 0)
   const scope = closure.createScope([new Closure(node, 0, 1)])
   expect(scope.name).toBe('lambda_0(lambda_1)')
 })
开发者ID:evansb,项目名称:source-toolchain,代码行数:7,代码来源:Closure.ts


示例5: getAST

    public async getAST(): Promise<ESTree.BaseNode> {
      if (!this.ast) {
        const file = await fs.readFile(this.filePath, 'utf8');
        this.ast = acorn.parse(file, {
          allowHashBang: true,
          allowReserved: true,
          sourceType: 'module',
        });
      }

      return this.ast;
    }
开发者ID:chrisseg,项目名称:vscode-azure-blockchain-ethereum,代码行数:12,代码来源:truffleConfig.ts


示例6: it

it('interprets simple program', () => {
  const generator = evalProgram(parse('1 + 2;'), createInterpreter())
  const states = []
  let g = generator.next()
  while (g.value.isRunning) {
    states.push(g.value)
    g = generator.next()
  }
  expect(states.length).toBe(7)
  expect(states[0].node!.type).toBe('ExpressionStatement')
  expect(states[1].node!.type).toBe('BinaryExpression')
  expect(states[2].node!.type).toBe('Literal')
  expect(states[3].node!.type).toBe('Literal')
  expect(states[4].node!.type).toBe('Literal')
  expect(states[5].node!.type).toBe('Literal')
  expect(states[6].node!.type).toBe('BinaryExpression')
})
开发者ID:evansb,项目名称:source-toolchain,代码行数:17,代码来源:interpreter.ts


示例7: bundle

export function bundle(options: IBundleOptions, host: IHost = new DefaultHost()): string {
  const context: IPaeckchenContext = {
    config: createConfig(options, host),
    host
  };
  if (!context.config.input.entryPoint) {
    throw new Error('Missing entry-point');
  }

  const detectedGlobals: IDetectedGlobals = {
    global: false,
    process: false,
    buffer: false
  };
  const paeckchenAst = parse(paeckchenSource);
  const modules = getModules(paeckchenAst).elements;
  const absoluteEntryPath = join(host.cwd(), context.config.input.entryPoint);
  // start bundling...
  enqueueModule(getModulePath('.', absoluteEntryPath, context));
  while (bundleNextModule(modules, context, detectedGlobals)) {
    process.stderr.write('.');
  }
  // ... when ready inject globals...
  injectGlobals(detectedGlobals, paeckchenAst, context);
  // ... and bundle global dependencies
  while (bundleNextModule(modules, context, detectedGlobals)) {
    process.stderr.write('.');
  }
  process.stderr.write('\n');

  const bundleResult = generate(paeckchenAst, {
    comment: true
  });
  if (context.config.output.file) {
    host.writeFile(
      host.joinPath(context.config.output.folder, context.config.output.file),
        bundleResult);
    return undefined;
  }
  return bundleResult;
}
开发者ID:ZauberNerd,项目名称:paeckchen,代码行数:41,代码来源:bundle.ts


示例8: createContext

export const parse = (source: string, state: StaticState | number) => {
  if (typeof state === 'number') {
    state = createContext({ week: state })
  }
  try {
    const program = acornParse(source, createAcornParserOptions(state))
    state.parser.program = program
    state.cfg.scopes[0].node = program
    simple(program, walkers, undefined, state)
  } catch (error) {
    if (error instanceof SyntaxError) {
      const loc = (error as any).loc
      const location = {
        start: { line: loc.line, column: loc.column },
        end: { line: loc.line, column: loc.column + 1 }
      }
      const message = error.toString()
      state.parser.errors.push(new FatalSyntaxError(location, error.toString()))
    } else {
      throw error
    }
  }
  return state
}
开发者ID:evansb,项目名称:source-toolchain,代码行数:24,代码来源:parser.ts



注:本文中的acorn.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript acorn.parseExpressionAt函数代码示例发布时间:2022-05-28
下一篇:
TypeScript account.toggleFavourite函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap