UNPKG

ts-macro

Version:
4 lines (3 loc) 3.13 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;var _mugglestring = require('muggle-string');var g={completion:!0,format:!0,navigation:!0,semantic:!0,structure:!0,verification:!0},l= exports.TsmVirtualCode = (_class =class{constructor(n,t,e="tsx",a=[]){;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);this.filePath=n;this.ast=t;this.languageId=e;this.plugins=a;this.id=`root_${this.languageId}`,this.codes.push([t.text,void 0,0,g]);for(let o of this.plugins)try{_optionalChain([o, 'access', _ => _.resolveVirtualCode, 'optionalCall', _2 => _2(this)])}catch(i){console.error(`[${o.name}]:`,i)}_optionalChain([t, 'access', _3 => _3.statements, 'access', _4 => _4[0], 'optionalAccess', _5 => _5.kind])!==272&&this.codes.unshift(`/* placeholder */ `,[` `,void 0,0,g]),this.mappings=c(this.codes);let s=_mugglestring.toString.call(void 0, this.codes);this.snapshot={getLength:()=>s.length,getText:(o,i)=>s.slice(o,i),getChangeRange(){}}}__init() {this.embeddedCodes=[]}__init2() {this.codes=[]}}, _class);function c(r){let n=0,t=[];for(let e of r)typeof e=="string"?n+=e.length:(t.push({sourceOffsets:[e[2]],generatedOffsets:[n],lengths:[e[0].length],data:e[3]}),n+=e[0].length);return t}function h(r){return r}function P(r){return n=>{if(_optionalChain([n, 'optionalAccess', _6 => _6.modules])){let t=r({ts:n.modules.typescript,...n});return(Array.isArray(t)?t:[t]).flatMap(e=>(e.resolveVirtualCode&&(e.resolveEmbeddedCode??=(a,s,o)=>{for(let i of["script","scriptSetup"]){let u=_optionalChain([s, 'access', _7 => _7[i], 'optionalAccess', _8 => _8.ast]);u&&e.resolveVirtualCode({ast:u,source:i,filePath:a,id:o.id,codes:o.content,languageId:o.lang,embeddedCodes:o.embeddedCodes,linkedCodeMappings:o.linkedCodeMappings})}}),e.order??=e.enforce==="pre"?-1:e.enforce==="post"?1:0,e.version??=2.1,e))}return t=>r(t,n)}}function I(r,n,t,...e){return _mugglestring.replaceSourceRange.call(void 0, r,void 0,n,t,...e)}exports.TsmVirtualCode = l; exports.allCodeFeatures = g; exports.create = _mugglestring.create; exports.createPlugin = P; exports.defineConfig = h; exports.getLength = _mugglestring.getLength; exports.getStack = _mugglestring.getStack; exports.offsetStack = _mugglestring.offsetStack; exports.replace = _mugglestring.replace; exports.replaceAll = _mugglestring.replaceAll; exports.replaceRange = I; exports.replaceSourceRange = _mugglestring.replaceSourceRange; exports.resetOffsetStack = _mugglestring.resetOffsetStack; exports.setTracking = _mugglestring.setTracking; exports.toString = _mugglestring.toString; exports.track = _mugglestring.track;