Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,015 changes: 1,817 additions & 1,198 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "./dist/index.js",
"types": "./dist/src/index.d.ts",
"type": "module",
"sideEffects": false,
"license": "LGPL-3.0",
"author": "Sébastien Piquemal",
"private": false,
Expand All @@ -14,10 +15,11 @@
"scripts": {
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' npx jest --config node_modules/@webpd/dev/configs/jest.js",
"build:dist": "npx rollup --config node_modules/@webpd/dev/configs/dist.rollup.mjs",
"build": "npm run clean ; npm run build:dist",
"build": "npm run clean && npm run build:dist",
"build:dev:full": "npm run build",
"clean": "rm -rf dist",
"prettier": "prettier --write --config node_modules/@webpd/dev/configs/prettier.json",
"postpublish": "git tag -a v$(node -p \"require('./package.json').version\") -m \"Release $(node -p \"require('./package.json').version\")\" ; git push --tags"
"postpublish": "git tag -a v$(node -p \"require('./package.json').version\") -m \"Release $(node -p \"require('./package.json').version\")\" && git push --tags"
},
"repository": {
"type": "git",
Expand All @@ -28,6 +30,6 @@
},
"homepage": "https://github.com/sebpiq/WebPd_pd-parser#readme",
"devDependencies": {
"@webpd/dev": "github:sebpiq/WebPd_dev#v1"
"@webpd/dev": "github:sebpiq/WebPd_dev#v2"
}
}
4 changes: 2 additions & 2 deletions src/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ export const hydrateNodePatch = (

export const hydrateNodeArray = (
id: PdJson.LocalId,
{ tokens }: TokenizedLine
arrayId: PdJson.GlobalId,
): PdJson.ArrayNode => ({
id,
args: [],
type: 'array',
nodeClass: 'array',
arrayId: parseStringToken(tokens[1]),
arrayId: arrayId,
layout: {},
})

Expand Down
111 changes: 56 additions & 55 deletions src/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import parse, {
_parsePatches,
nextPatchId,
nextArrayId,
nextUniqueArrayName,
Compilation,
DEFAULT_ARRAY_SIZE,
} from './parse'
Expand Down Expand Up @@ -56,6 +57,7 @@ describe('parse', () => {
beforeEach(() => {
nextPatchId.counter = -1
nextArrayId.counter = -1
nextUniqueArrayName.counter = -1
})

describe('_parsePatches', () => {
Expand Down Expand Up @@ -617,12 +619,9 @@ describe('parse', () => {
assert.ok(parseResult.status === 0)
const { pd } = parseResult

assert.deepStrictEqual(Object.keys(pd.patches), ['0', '1', '2'])
assert.deepStrictEqual(Object.keys(pd.patches), ['0'])
assert.deepStrictEqual(Object.keys(pd.arrays), ['0'])
const patch = pd.patches['0']!
const graphSubpatch = pd.patches['1']!
const arraySubpatch = pd.patches['2']!

const array = pd.arrays['0']!

assert.deepStrictEqual<PdJson.Patch>(patch, {
Expand All @@ -639,78 +638,85 @@ describe('parse', () => {
'0': {
id: '0',
type: 'table',
nodeClass: 'subpatch',
args: [],
nodeClass: 'generic',
args: ['myTable', 35],
layout: { x: 290, y: 57 },
patchId: '1',
},
},
connections: [],
inlets: [],
outlets: [],
})

assert.deepStrictEqual<PdJson.Patch>(graphSubpatch, {
id: '1',
isRoot: false,
layout: {
openOnLoad: 0,
windowX: 0,
windowY: 0,
windowWidth: 100,
windowHeight: 100,
},
args: [],
nodes: {
'0': {
id: '0',
type: 'graph',
nodeClass: 'subpatch',
patchId: '2',
args: [],
layout: {
x: 0,
y: 0,
},
},
},
connections: [],
inlets: [],
outlets: [],
assert.deepStrictEqual<PdJson.PdArray>(array, {
id: '0',
args: ['myTable', 35, 0],
layout: { drawAs: 'polygon' },
data: null,
})
})

assert.deepStrictEqual<PdJson.Patch>(arraySubpatch, {
id: '2',
isRoot: false,
it('should parse array define rightly', () => {
const parseResult = parse(TEST_PATCHES.arrayDefine)
assert.ok(parseResult.status === 0)
const { pd } = parseResult

assert.deepStrictEqual(Object.keys(pd.patches), ['0'])
assert.deepStrictEqual(Object.keys(pd.arrays), ['0', '1'])
const patch = pd.patches['0']!

const array0 = pd.arrays['0']!
const array1 = pd.arrays['1']!

// Unique array name generated if none is provided in the node.
const autoName = 'table0'

assert.deepStrictEqual<PdJson.Patch>(patch, {
id: '0',
isRoot: true,
layout: {
openOnLoad: 0,
windowX: 0,
windowY: 0,
windowWidth: 100,
windowHeight: 100,
windowX: 873,
windowY: 356,
windowWidth: 450,
windowHeight: 300,
},
args: [],
nodes: {
'0': {
id: '0',
type: 'array',
nodeClass: 'array',
arrayId: '0',
args: [],
layout: {},
nodeClass: 'generic',
args: ['define', '-k', autoName],
layout: { x: 98, y: 145 },
},
"1": {
id: "1",
type: "array",
nodeClass: "generic",
args: ["define", "-k", "BLA", 10],
layout: {"x": 93, "y": 75},
}
},
connections: [],
inlets: [],
outlets: [],
})

assert.deepStrictEqual<PdJson.PdArray>(array, {
assert.deepStrictEqual<PdJson.PdArray>(array0, {
id: '0',
args: ['myTable', 35, 0],
layout: { drawAs: 'polygon' },
args: [autoName, 100, 0],
layout: {"drawAs": "polygon"},
data: null,
})

assert.deepStrictEqual<PdJson.PdArray>(array1, {
id: '1',
args: ['BLA', 10, 1],
layout: {"drawAs": "polygon"},
data: [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
],
})
})

it('should parse graphs rightly', () => {
Expand Down Expand Up @@ -1041,12 +1047,7 @@ describe('parse', () => {
const parseResult = parse(pdTableWithoutSize)
assert.ok(parseResult.status === 0)
const pd = parseResult.pd
assert.deepStrictEqual(Object.keys(pd.patches), ['0', '1', '2'])

const arrayNode = pd.patches['2']!.nodes['0']!
assert.ok(arrayNode.nodeClass === 'array')
assert.deepStrictEqual(arrayNode.type, 'array')
assert.deepStrictEqual(arrayNode.arrayId, '0')
assert.deepStrictEqual(Object.keys(pd.patches), ['0'])

assert.deepStrictEqual(Object.keys(pd.arrays), ['0'])
const array = pd.arrays['0']!
Expand Down
Loading
Loading