king-design-analyzer
king-design-analyzer
AST-based code analyzer for King Design Vue components with on-demand modular imports.
Installation
npm install king-design-analyzer
Features
| Module | Import Path | Description |
|---|---|---|
| Static Check | king-design-analyzer/static |
SFC structure & syntax validation |
| AST Analysis | king-design-analyzer/ast |
Component rules, props, events, slots checking |
| Runtime | king-design-analyzer/runtime |
Script execution pre-check |
| Full | king-design-analyzer/full |
All three layers combined |
Usage
On-demand Import (Recommended)
// Only static check - minimal bundle size
import { validateCompilation, compileSFC } from 'king-design-analyzer/static';
// Only AST analysis
import { analyzeCodeWithAST, componentRegistry } from 'king-design-analyzer/ast';
// Only runtime detection
import { validateRuntimePrecheck } from 'king-design-analyzer/runtime';
// Full validation (compilation + AST + runtime)
import { validateCode, validateCodeSync } from 'king-design-analyzer/full';
Full Import
import {
validateCode,
analyzeCodeWithAST,
compileSFC,
validateCompilation,
validateRuntimePrecheck
} from 'king-design-analyzer';
API Reference
Static Module (/static)
// Validate SFC structure and syntax
function validateCompilation(code: string): ValidationLayer;
// Compile Vue SFC, extract template/script/style
function compileSFC(code: string, scopeId: string): CompilationResult;
interface ValidationLayer {
name: string;
passed: boolean;
errors: string[];
}
AST Module (/ast)
// Analyze code for component rule violations
async function analyzeCodeWithAST(code: string): Promise<RuleViolation[]>;
// Component metadata registry
const componentRegistry: ComponentRegistry;
interface RuleViolation {
rule: string;
match: string;
suggestion: string;
}
Runtime Module (/runtime)
// Pre-check if script can execute correctly
function validateRuntimePrecheck(code: string): ValidationLayer;
Full Module (/full)
// Full validation with all three layers (async)
async function validateCode(code: string): Promise<UnifiedValidationResult>;
// Sync version without AST check
function validateCodeSync(code: string): SyncValidationResult;
interface UnifiedValidationResult {
passed: boolean;
layers: {
compilation: ValidationLayer;
ast: ValidationLayer;
runtime: ValidationLayer;
};
summary: string;
}
Example
import { validateCode } from 'king-design-analyzer/full';
const code = `
<script setup lang="ts">
import { Button } from '@king-design/vue';
import { ref } from 'vue';
const count = ref(0);
</script>
<template>
<Button @click="count++">{{ count }}</Button>
</template>
`;
const result = await validateCode(code);
if (result.passed) {
console.log('✅ All checks passed');
} else {
console.log('❌ Validation failed:', result.summary);
result.layers.compilation.errors.forEach(e => console.log(' Compile:', e));
result.layers.ast.errors.forEach(e => console.log(' AST:', e));
result.layers.runtime.errors.forEach(e => console.log(' Runtime:', e));
}
Peer Dependencies
For full functionality, install these peer dependencies:
npm install @vue/compiler-sfc typescript
Note:
@vue/compiler-sfcis required for AST analysis.typescriptis optional.
License
MIT
Related Packages
Version History
| Version | Released | License |
|---|---|---|
| 2.2.8 | MIT | |
| 2.2.6 | MIT | |
| 2.2.5 | MIT | |
| 2.2.4 | MIT | |
| 2.2.3 | MIT | |
| 2.2.2 | MIT | |
| 2.2.1 | MIT | |
| 2.2.0 | MIT | |
| 2.1.9 | MIT | |
| 2.1.7 | MIT | |
| 2.1.6 | MIT | |
| 2.1.5 | MIT | |
| 2.1.4 | MIT | |
| 2.1.3 | MIT | |
| 2.1.2 | MIT | |
| 2.1.1 | MIT | |
| 2.1.0 | MIT | |
| 2.0.3 | MIT | |
| 2.0.2 | MIT | |
| 2.0.1 | MIT | |
| 2.0.0 | MIT | |
| 1.1.0 | MIT | |
| 1.0.6 | MIT | |
| 1.0.4 | MIT | |
| 1.0.3 | MIT | |
| 1.0.2 | MIT | |
| 1.0.1 | MIT | |
| 1.0.0 | MIT |