ktsn / vue-template-diagnostic

Diagnostic for expressions of Vue.js templates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vue-template-diagnostic

Example

import {
  createComponentHost,
  createTypeRepository,
  parseExpression,
  checkExpression
} from 'vue-template-diagnostic'

// Create TypeScript context
const checker = program.getTypeChecker()
const context = { ts, program, checker }

// Create a type repository
const repository = createTypeRepository(context)

// Get a TypeScript source file of a Vue.js component somehow
const source = program.getSourceFile('/path/to/component.ts')

// Create a component host
const host = createComponentHost(source, context)
if (host) {
  // Parse an expression in a Vue.js template
  const exp = parseExpression('"Hello, " + msg')

  if (!exp.failed) {
    // Check the parsed expression.
    // Must be provided a variables scope (you can use `host.members`)
    // and type repository
    const diagnostics = checkExpression(exp.value, host.members, repository)

    console.log(diagnostics)
  }
}

License

MIT

About

Diagnostic for expressions of Vue.js templates

License:MIT License


Languages

Language:TypeScript 100.0%