Skip to content

Commit

Permalink
feat: hides macro parameters starting with "_" (#1485)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas authored Aug 20, 2024
1 parent 3f1d22e commit 872e9d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/util/__tests__/gcode-macro-params.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { gcodeMacroParamDefault } from '../gcode-macro-params'
import gcodeMacroParams, { gcodeMacroParamDefault } from '../gcode-macro-params'

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) %}', []]
])('Expects params of "%s", to be %s', (param, expected) => {
expect(gcodeMacroParams(param)).toStrictEqual(expected)
})
})

describe('gcodeMacroParamDefault', () => {
it.each([
Expand Down
4 changes: 2 additions & 2 deletions src/util/gcode-macro-params.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const paramRegExp = /params\.(\w+)(.*)/gi
const defaultValueRegExp = /\|\s*default\s*\(\s*((["'])(?:\\\2|.)*?\2|-?[0-9][^,)]*)/i
const paramRegExp = /params\.([^_]\w*)(.*)/gi
const defaultValueRegExp = /\|\s*default\s*\(\s*((["'])(?:\\\2|.)*?\2|-?\d[^,)]*)/i

export const gcodeMacroParamDefault = (param: string) => {
const valueMatch = defaultValueRegExp.exec(param)
Expand Down

0 comments on commit 872e9d8

Please sign in to comment.