Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parseVueTemplate(text: string): string {
const doc = TextDocument.create('test://test/test.vue', 'vue', 0, text);
const regions = getVueDocumentRegions(doc);
const template = regions.getSingleTypeDocument('template');
if (template.languageId !== 'vue-html') {
return '';
}
const rawText = template.getText();
// skip checking on empty template
if (rawText.replace(/\s/g, '') === '') {
return '';
}
return rawText.replace(/ {10}/, '<template>') + '</template>';
}
return function test([value]: TemplateStringsArray) {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
const document = TextDocument.create(setup.docUri, setup.langId, 0, value);
const position = document.positionAt(offset);
const items = setup.doComplete(document, position).items;
return new CompletionAsserter(items, document);
};
}
const oldContent = document.getText();
let newContent = oldContent
.split('\n')
.map(line => ' '.repeat(line.length))
.join('\n');
let langId: string = defaultLanguageIdForBlockTypes[type];
for (const r of regions) {
if (r.type === type) {
newContent = newContent.slice(0, r.start) + oldContent.slice(r.start, r.end) + newContent.slice(r.end);
langId = r.languageId;
}
}
return TextDocument.create(document.uri, langId, document.version, newContent);
}
protected createDocument(uri: string, language: string, content: string): boolean {
if (this.isOpened(uri)) {
return false;
}
this._documents[uri] = TextDocument.create(uri, language, 1, content);
return true;
}
export function indexToPosition(text: string, index: number): Position {
const document = TextDocument.create("", "", 1, text);
return document.positionAt(index);
}
function getSourceDoc(fileName: string, program: ts.Program): TextDocument {
const sourceFile = program.getSourceFile(fileName)!;
return TextDocument.create(fileName, 'vue', 0, sourceFile.getFullText());
}
protected updateDocument(uri: string, content: string): boolean {
const document = this._documents[uri];
if (!document) {
return false;
}
if (document.getText() === content) {
return false;
}
const version = document.version + 1;
this._documents[uri] = TextDocument.create(document.uri, document.languageId, version, content);
return true;
}
export function parseVueScript(text: string): string {
const doc = TextDocument.create('test://test/test.vue', 'vue', 0, text);
const regions = getVueDocumentRegions(doc);
const script = regions.getSingleTypeDocument('script');
return script.getText() || 'export default {};';
}
function getSourceDoc(fileName: string, program: ts.Program): TextDocument {
const sourceFile = program.getSourceFile(fileName)!;
return TextDocument.create(fileName, 'vue', 0, sourceFile.getFullText());
}