|
1 |
- {"version":3,"sources":["name.js"],"names":["Object","defineProperty","exports","value","util_1","require","isQuoted","s","startsWith","endsWith","nameTokenizer","typeEnd","num","tokens","i","type","spec","source","reduce","description","trimLeft","quotedGroups","split","length","name","postName","splitSpace","slice","brackets","optional","defaultValue","ch","isSpace","problems","push","code","message","line","number","critical","nameToken","parts","trim","undefined","join","test","default"],"mappings":"AAAA;;AACAA,MAAM,CAACC,cAAP,CAAsBC,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C;;AACA,MAAMC,MAAM,GAAGC,OAAH,kBAAZ;;AACA,MAAMC,QAAQ,GAAIC,CAAD,IAAOA,CAAC,IAAIA,CAAC,CAACC,UAAF,CAAa,GAAb,CAAL,IAA0BD,CAAC,CAACE,QAAF,CAAW,GAAX,CAAlD;AACA;AACA;AACA;AACA;;;AACA,SAASC,aAAT,GAAyB;AACrB,QAAMC,OAAO,GAAG,CAACC,GAAD,EAAM;AAAEC,IAAAA;AAAF,GAAN,EAAkBC,CAAlB,KAAwBD,MAAM,CAACE,IAAP,KAAgB,EAAhB,GAAqBH,GAArB,GAA2BE,CAAnE;;AACA,SAAQE,IAAD,IAAU;AACb;AACA,UAAM;AAAEH,MAAAA;AAAF,QAAaG,IAAI,CAACC,MAAL,CAAYD,IAAI,CAACC,MAAL,CAAYC,MAAZ,CAAmBP,OAAnB,EAA4B,CAA5B,CAAZ,CAAnB;AACA,UAAMM,MAAM,GAAGJ,MAAM,CAACM,WAAP,CAAmBC,QAAnB,EAAf;AACA,UAAMC,YAAY,GAAGJ,MAAM,CAACK,KAAP,CAAa,GAAb,CAArB,CAJa,CAKb;;AACA,QAAID,YAAY,CAACE,MAAb,GAAsB,CAAtB,IACAF,YAAY,CAAC,CAAD,CAAZ,KAAoB,EADpB,IAEAA,YAAY,CAACE,MAAb,GAAsB,CAAtB,KAA4B,CAFhC,EAEmC;AAC/BP,MAAAA,IAAI,CAACQ,IAAL,GAAYH,YAAY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AAJK,SAAnB;AAMA,eAAOvB,IAAP;AACH;AACJ;;AACDA,IAAAA,IAAI,CAACa,QAAL,GAAgBA,QAAhB;AACAb,IAAAA,IAAI,CAACQ,IAAL,GAAYA,IAAZ;AACAX,IAAAA,MAAM,CAACW,IAAP,GAAcgB,SAAd;AACA,QAAIV,YAAY,KAAKa,SAArB,EACI3B,IAAI,CAAC8B,OAAL,GAAehB,YAAf;AACJ,KAACjB,MAAM,CAACY,QAAR,EAAkBZ,MAAM,CAACM,WAAzB,IAAwCf,MAAM,CAACsB,UAAP,CAAkBT,MAAM,CAACU,KAAP,CAAad,MAAM,CAACW,IAAP,CAAYD,MAAzB,CAAlB,CAAxC;AACA,WAAOP,IAAP;AACH,GAjFD;AAkFH;;AACDd,OAAO,CAAC4C,OAAR,GAAkBpC,aAAlB","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst util_1 = require(\"../../util\");\nconst isQuoted = (s) => s && s.startsWith('\"') && s.endsWith('\"');\n/**\n * Splits remaining `spec.lines[].tokens.description` into `name` and `descriptions` tokens,\n * and populates the `spec.name`\n */\nfunction nameTokenizer() {\n const typeEnd = (num, { tokens }, i) => tokens.type === '' ? num : i;\n return (spec) => {\n // look for the name in the line where {type} ends\n const { tokens } = spec.source[spec.source.reduce(typeEnd, 0)];\n const source = tokens.description.trimLeft();\n const quotedGroups = source.split('\"');\n // if it starts with quoted group, assume it is a literal\n if (quotedGroups.length > 1 &&\n quotedGroups[0] === '' &&\n quotedGroups.length % 2 === 1) {\n spec.name = quotedGroups[1];\n tokens.name = `\"${quotedGroups[1]}\"`;\n [tokens.postName, tokens.description] = util_1.splitSpace(source.slice(tokens.name.length));\n return spec;\n }\n let brackets = 0;\n let name = '';\n let optional = false;\n let defaultValue;\n // assume name is non-space string or anything wrapped into brackets\n for (const ch of source) {\n if (brackets === 0 && util_1.isSpace(ch))\n break;\n if (ch === '[')\n brackets++;\n if (ch === ']')\n brackets--;\n name += ch;\n }\n if (brackets !== 0) {\n spec.problems.push({\n code: 'spec:name:unpaired-brackets',\n message: 'unpaired brackets',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n const nameToken = name;\n if (name[0] === '[' && name[name.length - 1] === ']') {\n optional = true;\n name = name.slice(1, -1);\n const parts = name.split('=');\n name = parts[0].trim();\n if (parts[1] !== undefined)\n defaultValue = parts.slice(1).join('=').trim();\n if (name === '') {\n spec.problems.push({\n code: 'spec:name:empty-name',\n message: 'empty name',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n if (defaultValue === '') {\n spec.problems.push({\n code: 'spec:name:empty-default',\n message: 'empty default value',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n // has \"=\" and is not a string, except for \"=>\"\n if (!isQuoted(defaultValue) && /=(?!>)/.test(defaultValue)) {\n spec.problems.push({\n code: 'spec:name:invalid-default',\n message: 'invalid default value syntax',\n line: spec.source[0].number,\n critical: true,\n });\n return spec;\n }\n }\n spec.optional = optional;\n spec.name = name;\n tokens.name = nameToken;\n if (defaultValue !== undefined)\n spec.default = defaultValue;\n [tokens.postName, tokens.description] = util_1.splitSpace(source.slice(tokens.name.length));\n return spec;\n };\n}\nexports.default = nameTokenizer;\n"],"file":"name.cjs"}
|