fix: handle broken parse
This commit is contained in:
parent
908a6fd986
commit
94685e4654
|
@ -22,39 +22,48 @@ function computeParams(ancestors) {
|
|||
}
|
||||
|
||||
export function parseLetters(source) {
|
||||
const tree = parser.parse(source);
|
||||
tree.dialogue = {
|
||||
name: 'rate',
|
||||
params: {frequency: 0.05, length: 0},
|
||||
};
|
||||
const letters = [];
|
||||
visit(tree, (node, ancestors) => {
|
||||
switch (node.type) {
|
||||
case 'mdxJsxFlowElement':
|
||||
case 'mdxJsxTextElement': {
|
||||
node.dialogue = {name: node.name, params: {length: 0}};
|
||||
for (const {name, value: {value}} of node.attributes) {
|
||||
node.dialogue.params[name] = value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'text': {
|
||||
const params = computeParams(ancestors);
|
||||
const split = node.value.split('');
|
||||
for (let i = 0; i < split.length; ++i) {
|
||||
const indices = {};
|
||||
for (const name in params) {
|
||||
indices[name] = i + params[name].length;
|
||||
let letters = [];
|
||||
try {
|
||||
const tree = parser.parse(source);
|
||||
tree.dialogue = {
|
||||
name: 'rate',
|
||||
params: {frequency: 0.05, length: 0},
|
||||
};
|
||||
visit(tree, (node, ancestors) => {
|
||||
switch (node.type) {
|
||||
case 'mdxJsxFlowElement':
|
||||
case 'mdxJsxTextElement': {
|
||||
node.dialogue = {name: node.name, params: {length: 0}};
|
||||
for (const {name, value: {value}} of node.attributes) {
|
||||
node.dialogue.params[name] = value;
|
||||
}
|
||||
letters.push({character: split[i], indices, params});
|
||||
break;
|
||||
}
|
||||
for (const name in params) {
|
||||
params[name].length += split.length;
|
||||
case 'text': {
|
||||
const params = computeParams(ancestors);
|
||||
const split = node.value.split('');
|
||||
for (let i = 0; i < split.length; ++i) {
|
||||
const indices = {};
|
||||
for (const name in params) {
|
||||
indices[name] = i + params[name].length;
|
||||
}
|
||||
letters.push({character: split[i], indices, params});
|
||||
}
|
||||
for (const name in params) {
|
||||
params[name].length += split.length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
letters = source.split('').map((character) => (({
|
||||
character,
|
||||
indices: {},
|
||||
params: {rate: {frequency: 0.05}},
|
||||
})));
|
||||
}
|
||||
return letters;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user