Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dc8fc30

Browse files
author
Ye Wei
committedMar 23, 2025·
support pipelineOperator for babel parser
1 parent 0536231 commit dc8fc30

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed
 

‎composables/parser/javascript/BabelGui.vue

+70-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,54 @@ const decoratorsLegacy = useOptions(
9797
}
9898
},
9999
)
100+
101+
const pipelineOperator = useOptions(
102+
(opt: ParserOptions) =>
103+
opt.plugins?.some((n) => Array.isArray(n) && n[0] === 'pipelineOperator'),
104+
(value, opt) => {
105+
if (!Array.isArray(opt.plugins)) opt.plugins = []
106+
if (value) {
107+
opt.plugins.push([
108+
'pipelineOperator',
109+
{ proposal: 'hack', topicToken: '#' },
110+
])
111+
} else {
112+
opt.plugins = opt.plugins.filter(
113+
(n) => !Array.isArray(n) || n[0] !== 'pipelineOperator',
114+
)
115+
}
116+
},
117+
)
118+
119+
function findPipelineOperator(optPlugins: ParserOptions['plugins']) {
120+
return optPlugins?.find(
121+
(n) => Array.isArray(n) && n[0] === 'pipelineOperator',
122+
)
123+
}
124+
125+
const pipelineOperatorProposal = useOptions(
126+
(opt: ParserOptions) => findPipelineOperator(opt.plugins)?.[1].proposal,
127+
(value, opt) => {
128+
const pipelineOperator = findPipelineOperator(opt.plugins)
129+
if (!pipelineOperator) return
130+
if (value === 'fsharp') {
131+
pipelineOperator[1].proposal = value
132+
delete pipelineOperator[1].topicToken
133+
} else if (value === 'hack') {
134+
pipelineOperator[1].proposal = value
135+
pipelineOperator[1].topicToken = '#'
136+
}
137+
},
138+
)
139+
const pipelineOperatorTopicToken = useOptions(
140+
(opt: ParserOptions) => findPipelineOperator(opt.plugins)?.[1].topicToken,
141+
(value, opt) => {
142+
const pipelineOperator = findPipelineOperator(opt.plugins)
143+
if (!pipelineOperator) return
144+
pipelineOperator[1].topicToken = value
145+
},
146+
)
147+
100148
const decoratorAutoAccessors = usePlugin('decoratorAutoAccessors', [decorators])
101149
const decimal = usePlugin('decimal')
102150
const deferredImportEvaluation = usePlugin('deferredImportEvaluation')
@@ -110,7 +158,6 @@ const importReflection = usePlugin('importReflection')
110158
const moduleBlocks = usePlugin('moduleBlocks')
111159
const optionalChainingAssign = usePlugin('optionalChainingAssign')
112160
const partialApplication = usePlugin('partialApplication')
113-
const pipelineOperator = usePlugin('pipelineOperator')
114161
const recordAndTuple = usePlugin('recordAndTuple')
115162
const sourcePhaseImports = usePlugin('sourcePhaseImports')
116163
const throwExpressions = usePlugin('throwExpressions')
@@ -271,6 +318,28 @@ const throwExpressions = usePlugin('throwExpressions')
271318
<span>pipelineOperator</span>
272319
</label>
273320

321+
<label ml6>
322+
<span>proposal</span>
323+
<select v-model="pipelineOperatorProposal" :disabled="!pipelineOperator">
324+
<option value="hack">hack</option>
325+
<option value="fsharp">fsharp</option>
326+
</select>
327+
</label>
328+
329+
<label ml6>
330+
<span>topicToken</span>
331+
<select
332+
v-model="pipelineOperatorTopicToken"
333+
:disabled="!pipelineOperator || pipelineOperatorProposal !== 'hack'"
334+
>
335+
<option value="%">%</option>
336+
<option value="#">#</option>
337+
<option value="^">^</option>
338+
<option value="@@">@@</option>
339+
<option value="^^">^^</option>
340+
</select>
341+
</label>
342+
274343
<label>
275344
<!-- Stage 2 -->
276345
<input v-model="functionSent" type="checkbox" switch />

0 commit comments

Comments
 (0)
Please sign in to comment.