Skip to content

Commit

Permalink
refactor: handling of macro parameters "_" prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas committed Aug 20, 2024
1 parent 872e9d8 commit c1dc2ae
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/widgets/macros/MacroBtn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default class MacroBtn extends Mixins(StateMixin) {
this.$set(this.params, 'message', { value: '', reset: '' })
} else {
for (const { name, value } of gcodeMacroParams(this.macro.config.gcode)) {
if (!this.params[name]) {
if (!name.startsWith('_') && !this.params[name]) {
this.$set(this.params, name, { value, reset: value })
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/__tests__/gcode-macro-params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ describe('gcodeMacroParams', () => {
it.each([
['{% set ENABLE = params.ENABLE %}', [{ name: 'ENABLE', value: '' }]],
['{% set ENABLE = params.ENABLE | default(1) %}', [{ name: 'ENABLE', value: '1' }]],
['{% set ENABLE = params._ENABLE %}', []],
['{% set ENABLE = params._ENABLE | default(1) %}', []]
['{% set ENABLE = params._ENABLE %}', [{ name: '_ENABLE', value: '' }]],
['{% set ENABLE = params._ENABLE | default(1) %}', [{ name: '_ENABLE', value: '1' }]]
])('Expects params of "%s", to be %s', (param, expected) => {
expect(gcodeMacroParams(param)).toStrictEqual(expected)
})
Expand Down
2 changes: 1 addition & 1 deletion src/util/gcode-macro-params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const paramRegExp = /params\.([^_]\w*)(.*)/gi
const paramRegExp = /params\.(\w+)(.*)/gi
const defaultValueRegExp = /\|\s*default\s*\(\s*((["'])(?:\\\2|.)*?\2|-?\d[^,)]*)/i

export const gcodeMacroParamDefault = (param: string) => {
Expand Down

0 comments on commit c1dc2ae

Please sign in to comment.