How to use the edge-parser.Parser function in edge-parser

To help you get started, we’ve selected a few edge-parser 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 edge-js / edge / test / utils.spec.ts View on Github external
test('return true if token is block level matching token', (assert) => {
    const parser = new Parser(tags, { filename: 'foo.edge' })

    const tokens = parser.generateLexerTokens(dedent`@if()
      @endif
    `)

    assert.isTrue(isBlockToken(tokens[0], 'if'))
    assert.isFalse(isBlockToken(tokens[0], 'elseif'))
  })
github edge-js / edge / test / utils.spec.ts View on Github external
test('parse props with more than one assignment expression', (assert) => {
    const parser = new Parser(tags, { filename: 'foo.edge' })
    const expression = parser.acornToEdgeExpression(
      parser.generateAcornExpression(`(title = 'Hello', body = 'Some content')`, loc),
    )

    const props = expressionsToStringifyObject(expression.expressions, parser)
    assert.equal(props, `{ title: 'Hello', body: 'Some content' }`)
  })
})
github edge-js / edge / test / sequence-expression.spec.ts View on Github external
test('parse props with multiple obj properties', (assert) => {
    const parser = new Parser(tags, { filename: 'foo.edge' })
    const ast = parser.generateAst(`('partial', { username: 'virk', age: 22 })`, loc).body[0]
    const expression = parser.acornToEdgeExpression(ast)
    const [name, props] = parseSequenceExpression(expression, parser)
    assert.equal(name, `'partial'`)
    assert.equal(props, `{ username: 'virk', age: 22 }`)
  })
github edge-js / edge / src / Compiler / index.ts View on Github external
public generateLexerTokens (templatePath: string): ParserToken[] {
    const { template } = this._loader.resolve(templatePath, false)

    const parser = new Parser(this._tags, { filename: templatePath })
    return this._templateContentToTokens(template, parser, templatePath)
  }
github edge-js / edge / src / Compiler / index.ts View on Github external
/**
     * Do not load presenter in inline mode
     */
    const loadPresenter = !inline

    /**
     * Inline templates are not wrapped inside a function
     * call. They share the parent template scope
     */
    const wrapAsFunction = !inline

    /**
     * Get a new instance of the parser. We use the `templatePath` as the filename
     * instead of the `absPath`, since `templatePath` is relative and readable.
     */
    const parser = new Parser(this._tags, {
      filename: `${absPath.replace(/\.edge$/, '')}.edge`,
    })

    /**
     * Resolve the template and Presenter using the given loader
     */
    const { template, Presenter } = this._loader.resolve(absPath, loadPresenter)

    /**
     * Convert template to AST. The AST will have the layout actions merged (if layout)
     * is used.
     */
    const templateTokens = this._templateContentToTokens(template, parser, absPath)

    /**
     * Finally process the ast