Skip to content

Commit

Permalink
Merge pull request #7 from Himenon/dev
Browse files Browse the repository at this point in the history
updated(code): memorizeとbabel-standaloneのコードを追加
  • Loading branch information
Himenon committed Oct 14, 2018
2 parents 902c398 + 5887037 commit b946351
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 7 deletions.
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--install.ignore-engines true
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
#### 1.0.4 (2018-10-14)

##### New Features

* **express-session:**
* sessionの動作確認と、テストの追加 (30ee9a2f)
* express-sessionの動作検証を追加 (cdb5ad48)

##### Other Changes

* **code:**
* transformJSX + @babel/standaloneのコード (bc7283a7)
* memorizeとstandaloneのコードを追加 (80daa2f3)
* **add:**
* new Functionを用いたReact.createElementの実験 (c552642a)
* 検証内容の追加 (4452fbcc)
* **pkg:** ライブラリのバージョン上げ (9c2f4fa2)
* **tslint:**
* fixした (d412d323)
* Linterを入れた (f0dcb5b9)

##### Tests

* **react:** reactのテストを追加 (302d3bb1)
* **express-session:**
* --forceExitを追加 (fd53d582)
* --detectOpenHandlesを追加 (598f5f48)
* jestが終了しない (4a945f73)
* テストの追加 (4e3a9b94)

#### 1.0.3 (2018-10-13)

##### New Features
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-one-shot",
"version": "1.0.3",
"version": "1.0.4",
"description": "Libraryの調査",
"main": "entry.js",
"author": "Himenon",
Expand Down Expand Up @@ -57,6 +57,8 @@
}
},
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/standalone": "^7.1.0",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
Expand Down
26 changes: 26 additions & 0 deletions src/babel-standalone/__tests__/oneshot.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import * as renderer from 'react-test-renderer';
import * as OneShot from "../oneshot";


test("parse", () => {
const codeString = OneShot.parse(`
function hello() {
return "Hello World";
}
`);
expect(codeString).not.toBeNull();
const hello = new Function(`return ${codeString}`)();
expect(hello()).toEqual("Hello World");
})

test("parse string that contain JSX", () => {
const codeString = OneShot.parseWithJSX(`<div>Hello World</div>`);
expect(codeString).toEqual('React.createElement("div", null, "Hello World");');
const componentCreator = new Function('React', `return ${codeString}`);

const component = componentCreator(React);
const testComponent = renderer.create(component);
const expectComponent = renderer.create(<div>Hello World</div>);
expect(testComponent.toJSON()).toEqual(expectComponent.toJSON());
});
14 changes: 14 additions & 0 deletions src/babel-standalone/oneshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-ignore
import * as standalone from "@babel/standalone";
// @ts-ignore
import * as transformJSX from '@babel/plugin-transform-react-jsx'

export const parse = (raw: string): string | null => {
return standalone.transform(raw, {}).code;
}

export const parseWithJSX = (raw: string): string | null => {
return standalone.transform(raw, {
plugins: [transformJSX],
}).code;
}
2 changes: 1 addition & 1 deletion src/express-session/oneshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ app.route('/logout')
);

portfinder.getPort({ port: 3000 }, (error: any, port: number) => {
server = app.listen(port, () => console.log(`Example app listening on port ${port}!`));
server = app.listen(port, () => process.stdout.write(`Example app listening on port ${port}!`));
});

export {
Expand Down
10 changes: 10 additions & 0 deletions src/high-order-component/__tests__/memorize.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { memorize } from "../memorize";

test("memorize", () => {
function add(a: number, b: number) {
return a + b;
}
const customAdd = memorize(add);
expect(customAdd(1, 2)).toEqual(3);
expect(customAdd(1, 2)).toEqual(3);
});
12 changes: 12 additions & 0 deletions src/high-order-component/memorize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function memorize<T extends Function>(f: T): any {
const cache: { [key: string]: T } = {}
return function fn() {
const key = arguments.length + Array.prototype.join.call(arguments, ",");
if (key in cache) {
return cache[key]
} else {
// @ts-ignore
return cache[key] = f.apply(this, arguments)
};
}
}
138 changes: 133 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,80 @@
# yarn lockfile v1


"@babel/code-frame@^7.0.0-beta.35":
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.0.0-beta.35":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8"
dependencies:
"@babel/highlight" "^7.0.0"

"@babel/core@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.1.2.tgz#f8d2a9ceb6832887329a7b60f9d035791400ba4e"
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.1.2"
"@babel/helpers" "^7.1.2"
"@babel/parser" "^7.1.2"
"@babel/template" "^7.1.2"
"@babel/traverse" "^7.1.0"
"@babel/types" "^7.1.2"
convert-source-map "^1.1.0"
debug "^3.1.0"
json5 "^0.5.0"
lodash "^4.17.10"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"

"@babel/generator@^7.1.2", "@babel/generator@^7.1.3":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.1.3.tgz#2103ec9c42d9bdad9190a6ad5ff2d456fd7b8673"
dependencies:
"@babel/types" "^7.1.3"
jsesc "^2.5.1"
lodash "^4.17.10"
source-map "^0.5.0"
trim-right "^1.0.1"

"@babel/helper-builder-react-jsx@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-builder-react-jsx/-/helper-builder-react-jsx-7.0.0.tgz#fa154cb53eb918cf2a9a7ce928e29eb649c5acdb"
dependencies:
"@babel/types" "^7.0.0"
esutils "^2.0.0"

"@babel/helper-function-name@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.1.0.tgz#a0ceb01685f73355d4360c1247f582bfafc8ff53"
dependencies:
"@babel/helper-get-function-arity" "^7.0.0"
"@babel/template" "^7.1.0"
"@babel/types" "^7.0.0"

"@babel/helper-get-function-arity@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz#83572d4320e2a4657263734113c42868b64e49c3"
dependencies:
"@babel/types" "^7.0.0"

"@babel/helper-plugin-utils@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250"

"@babel/helper-split-export-declaration@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz#3aae285c0311c2ab095d997b8c9a94cad547d813"
dependencies:
"@babel/types" "^7.0.0"

"@babel/helpers@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.1.2.tgz#ab752e8c35ef7d39987df4e8586c63b8846234b5"
dependencies:
"@babel/template" "^7.1.2"
"@babel/traverse" "^7.1.0"
"@babel/types" "^7.1.2"

"@babel/highlight@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0.tgz#f710c38c8d458e6dd9a201afb637fcb781ce99e4"
Expand All @@ -16,10 +84,58 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

"@babel/parser@^7.1.2", "@babel/parser@^7.1.3":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.1.3.tgz#2c92469bac2b7fbff810b67fca07bd138b48af77"

"@babel/plugin-syntax-jsx@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.0.0.tgz#034d5e2b4e14ccaea2e4c137af7e4afb39375ffd"
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-transform-react-jsx@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.0.0.tgz#524379e4eca5363cd10c4446ba163f093da75f3e"
dependencies:
"@babel/helper-builder-react-jsx" "^7.0.0"
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-jsx" "^7.0.0"

"@babel/standalone@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@babel/standalone/-/standalone-7.1.0.tgz#d79774a17e8df4a53def891864882f5d81c42001"

"@babel/template@^7.1.0", "@babel/template@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.1.2.tgz#090484a574fef5a2d2d7726a674eceda5c5b5644"
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/parser" "^7.1.2"
"@babel/types" "^7.1.2"

"@babel/traverse@^7.1.0":
version "7.1.4"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.1.4.tgz#f4f83b93d649b4b2c91121a9087fa2fa949ec2b4"
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.1.3"
"@babel/helper-function-name" "^7.1.0"
"@babel/helper-split-export-declaration" "^7.0.0"
"@babel/parser" "^7.1.3"
"@babel/types" "^7.1.3"
debug "^3.1.0"
globals "^11.1.0"
lodash "^4.17.10"

"@babel/types@^7.0.0", "@babel/types@^7.1.2", "@babel/types@^7.1.3":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.1.3.tgz#3a767004567060c2f40fca49a304712c525ee37d"
dependencies:
esutils "^2.0.2"
lodash "^4.17.10"
to-fast-properties "^2.0.0"

"@commitlint/cli@^7.2.1":
version "7.2.1"
resolved "https://registry.yarnpkg.com/@commitlint/cli/-/cli-7.2.1.tgz#dbb9eeb1f5015a129bb0801fbc1115eb1dcd513b"
Expand Down Expand Up @@ -964,7 +1080,7 @@ conventional-commits-parser@^2.1.0:
through2 "^2.0.0"
trim-off-newlines "^1.0.0"

convert-source-map@^1.4.0, convert-source-map@^1.5.1:
convert-source-map@^1.1.0, convert-source-map@^1.4.0, convert-source-map@^1.5.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.6.0.tgz#51b537a8c43e0f04dec1993bffcdd504e758ac20"
dependencies:
Expand Down Expand Up @@ -1299,7 +1415,7 @@ estraverse@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"

esutils@^2.0.2:
esutils@^2.0.0, esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"

Expand Down Expand Up @@ -1733,6 +1849,10 @@ global-dirs@^0.1.0:
dependencies:
ini "^1.3.4"

globals@^11.1.0:
version "11.8.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.8.0.tgz#c1ef45ee9bed6badf0663c5cb90e8d1adec1321d"

globals@^9.18.0:
version "9.18.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a"
Expand Down Expand Up @@ -2583,6 +2703,10 @@ jsesc@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b"

jsesc@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.1.tgz#e421a2a8e20d6b0819df28908f782526b96dd1fe"

json-parse-better-errors@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
Expand All @@ -2605,7 +2729,7 @@ json5@2.x:
dependencies:
minimist "^1.2.0"

json5@^0.5.1:
json5@^0.5.0, json5@^0.5.1:
version "0.5.1"
resolved "http://registry.npmjs.org/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

Expand Down Expand Up @@ -4015,7 +4139,7 @@ source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"

source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7:
source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7:
version "0.5.7"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"

Expand Down Expand Up @@ -4305,6 +4429,10 @@ to-fast-properties@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"

to-fast-properties@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"

to-object-path@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af"
Expand Down

0 comments on commit b946351

Please sign in to comment.