Skip to content

Commit

Permalink
Add mapping, linting, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessByte committed Oct 21, 2019
1 parent 0d04437 commit d9cc406
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"functions": false,
"typedefs": false
}
]
],
"import/no-unresolved": "off"
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.2.0

- Add `mapping` output
- Add `normalise` AST using mapped identifiers

## 0.1.0

:baby: initial release
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@exercism/javascript-representer",
"version": "0.1.0",
"version": "0.2.0",
"description": "Exercism AST representer for javascript",
"repository": "https://github.com/exercism/javascript-representer",
"author": "Derk-Jan Karrenbeld <[email protected]>",
Expand All @@ -24,25 +24,26 @@
"posttest": "yarn lint"
},
"devDependencies": {
"@babel/core": "^7.6.3",
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@babel/preset-typescript": "^7.6.0",
"@types/jest": "^24.0.18",
"@types/node": "^12.7.12",
"@types/jest": "^24.0.19",
"@types/node": "^12.11.1",
"@types/yargs": "^13.0.3",
"@typescript-eslint/eslint-plugin": "^2.3.3",
"@typescript-eslint/eslint-plugin": "^2.4.0",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.19.0",
"jest": "^24.9.0"
},
"dependencies": {
"@typescript-eslint/parser": "^2.3.3",
"@typescript-eslint/typescript-estree": "^2.3.3",
"@typescript-eslint/parser": "^2.4.0",
"@typescript-eslint/typescript-estree": "^2.4.0",
"esm": "^3.2.25",
"module-alias": "^2.2.2",
"typescript": "^3.6.3",
"typescript": "^3.6.4",
"yargs": "^14.2.0"
},
"_moduleAliases": {
Expand Down
9 changes: 7 additions & 2 deletions src/output/RepresenterAstOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ function normaliseRepresentation(
}
}

function findOrMapIdentifier(name: string, mapping: { [k: string]: string }) {
function findOrMapIdentifier(
name: string,
mapping: { [k: string]: string }
): string {
if (mapping[name]) {
return mapping[name]
}
Expand All @@ -59,7 +62,9 @@ function findOrMapIdentifier(name: string, mapping: { [k: string]: string }) {
return mapping[name]
}

function inverseMapping(mapping: { [k: string]: string }) {
function inverseMapping(mapping: {
[k: string]: string
}): { [k: string]: string } {
return Object.keys(mapping).reduce(
(result, original) => {
const mapped = mapping[original]
Expand Down
6 changes: 4 additions & 2 deletions test/output/processor/FileOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ describe('FileOutput', () => {
}),
OUT_OPTIONS
)
expect(processed).toStrictEqual(CONTENTS)
expect(processed).toStrictEqual({
representation: CONTENTS,
mapping: MAPPING,
})
})

it('writes the processable stream to disk', async () => {
Expand Down Expand Up @@ -131,7 +134,6 @@ describe('FileOutput', () => {
expect(files).toMatchObject({
[path.normalize(path.dirname(OUT_OPTIONS.output.representation))]: {
[outFile]: CONTENTS,
[OUT_OPTIONS.output.mapping]: MAPPING,
},
})

Expand Down
2 changes: 1 addition & 1 deletion test/output/processor/LogOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ describe('LogOutput', () => {
Promise.resolve({ representation: CONTENTS, mapping: MAPPING }),
DEFAULT_OPTIONS
)
expect(result).toBe({ representation: CONTENTS, mapping: MAPPING })
expect(result).toStrictEqual({ representation: CONTENTS, mapping: MAPPING })
})
})
Loading

0 comments on commit d9cc406

Please sign in to comment.