From cc602e1a4843935b7edf1f083729a7b543c87ede Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Tue, 27 Oct 2020 17:51:37 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=20MAJ=20TypeScript=20vers=204.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plein de nouveautés et notamment la possibilité de "programmer" les types chaînes littérales qui nous sera utile par exemple pour vérifier statiquement la validité d'une *expression* publicode dans `engine.evaluate`. https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/ ⬆ MAJ ESLint-typescript pour la compatibilité --- package.json | 6 +- .../source/components/mecanisms/Allègement.js | 1 - .../components/mecanisms/Composantes.js | 1 - .../mecanisms/InversionNumérique.js | 1 - .../source/components/mecanisms/Product.js | 1 - .../source/components/mecanisms/Somme.js | 2 +- .../source/components/mecanisms/Variations.js | 2 +- publicodes/source/components/rule/Examples.js | 1 - publicodes/source/evaluateReference.ts | 10 +- tsconfig.json | 2 +- yarn.lock | 100 +++++++++++++++--- 11 files changed, 97 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 0e2d22ddf..1938f1921 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,8 @@ "@types/webpack": "^4.41.10", "@types/webpack-bundle-analyzer": "^2.13.3", "@types/webpack-env": "^1.14.1", - "@typescript-eslint/eslint-plugin": "^4.0.1", - "@typescript-eslint/parser": "^4.0.1", + "@typescript-eslint/eslint-plugin": "^4.8.1", + "@typescript-eslint/parser": "^4.8.1", "autoprefixer": "^9.7.6", "babel-eslint": "^11.0.0-beta.0", "babel-jest": "^24.9.0", @@ -91,7 +91,7 @@ "style-loader": "^0.23.1", "terser-webpack-plugin": "^3.0.2", "toml-loader": "^1.0.0", - "typescript": "^4.0.2", + "typescript": "^4.1.0", "url-loader": "^4.1.0", "webpack": "^4.42.0", "webpack-bundle-analyzer": "^3.7.0", diff --git a/publicodes/source/components/mecanisms/Allègement.js b/publicodes/source/components/mecanisms/Allègement.js index 0ca5a1c34..81a10f02d 100644 --- a/publicodes/source/components/mecanisms/Allègement.js +++ b/publicodes/source/components/mecanisms/Allègement.js @@ -1,4 +1,3 @@ -import React from 'react' import { makeJsx } from '../../evaluation' import { Mecanism } from './common' diff --git a/publicodes/source/components/mecanisms/Composantes.js b/publicodes/source/components/mecanisms/Composantes.js index 31bbf80d2..3a0a79f54 100644 --- a/publicodes/source/components/mecanisms/Composantes.js +++ b/publicodes/source/components/mecanisms/Composantes.js @@ -1,5 +1,4 @@ import { toPairs } from 'ramda' -import React from 'react' import { Trans, useTranslation } from 'react-i18next' import styled from 'styled-components' import { makeJsx } from '../../evaluation' diff --git a/publicodes/source/components/mecanisms/InversionNumérique.js b/publicodes/source/components/mecanisms/InversionNumérique.js index 0d9546010..f4987c6be 100644 --- a/publicodes/source/components/mecanisms/InversionNumérique.js +++ b/publicodes/source/components/mecanisms/InversionNumérique.js @@ -1,4 +1,3 @@ -import React from 'react' import { makeJsx } from '../../evaluation' import { Mecanism } from './common' diff --git a/publicodes/source/components/mecanisms/Product.js b/publicodes/source/components/mecanisms/Product.js index 5bec94cc9..a552326cb 100644 --- a/publicodes/source/components/mecanisms/Product.js +++ b/publicodes/source/components/mecanisms/Product.js @@ -1,4 +1,3 @@ -import React from 'react' import { Trans } from 'react-i18next' import { makeJsx } from '../../evaluation' import { Mecanism } from './common' diff --git a/publicodes/source/components/mecanisms/Somme.js b/publicodes/source/components/mecanisms/Somme.js index 018448bb3..609bfbd88 100644 --- a/publicodes/source/components/mecanisms/Somme.js +++ b/publicodes/source/components/mecanisms/Somme.js @@ -1,5 +1,5 @@ import { path } from 'ramda' -import React, { useState } from 'react' +import { useState } from 'react' import { makeJsx } from '../../evaluation' import { Mecanism, NodeValuePointer } from './common' import styled from 'styled-components' diff --git a/publicodes/source/components/mecanisms/Variations.js b/publicodes/source/components/mecanisms/Variations.js index b278e831b..95f36ab95 100644 --- a/publicodes/source/components/mecanisms/Variations.js +++ b/publicodes/source/components/mecanisms/Variations.js @@ -1,5 +1,5 @@ import classnames from 'classnames' -import React, { useState } from 'react' +import { useState } from 'react' import emoji from 'react-easy-emoji' import { Trans, useTranslation } from 'react-i18next' import writtenNumbers from '../../locales/writtenNumbers.yaml' diff --git a/publicodes/source/components/rule/Examples.js b/publicodes/source/components/rule/Examples.js index 4d28a16ca..bb5aac7ac 100644 --- a/publicodes/source/components/rule/Examples.js +++ b/publicodes/source/components/rule/Examples.js @@ -1,5 +1,4 @@ import classNames from 'classnames' -import React from 'react' import { Trans } from 'react-i18next' export default function Examples({ rule, setCurrentExample, currentExample }) { diff --git a/publicodes/source/evaluateReference.ts b/publicodes/source/evaluateReference.ts index f2a898f9f..168fc6a32 100644 --- a/publicodes/source/evaluateReference.ts +++ b/publicodes/source/evaluateReference.ts @@ -59,10 +59,12 @@ Par défaut, seul le premier s'applique. Si vous voulez un autre comportement, v ...(explanation && { explanation }), - ...(explanation?.temporalValue && { - temporalValue: explanation.temporalValue - }), - ...(explanation?.unit && { unit: explanation.unit }), + ...(explanation?.temporalValue + ? { + temporalValue: explanation.temporalValue + } + : {}), + ...(explanation?.unit ? { unit: explanation.unit } : {}), missingVariables } return addReplacementMissingVariable(this.cache[cacheName]) diff --git a/tsconfig.json b/tsconfig.json index dc29470d4..71c646505 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "moduleResolution": "node", "module": "esnext", "target": "esnext", - "jsx": "react", + "jsx": "react-jsx", "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, diff --git a/yarn.lock b/yarn.lock index 5539089d5..c74b97dae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1791,6 +1791,19 @@ semver "^7.3.2" tsutils "^3.17.1" +"@typescript-eslint/eslint-plugin@^4.8.1": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.8.1.tgz#b362abe0ee478a6c6d06c14552a6497f0b480769" + integrity sha512-d7LeQ7dbUrIv5YVFNzGgaW3IQKMmnmKFneRWagRlGYOSfLJVaRbj/FrBNOBC1a3tVO+TgNq1GbHvRtg1kwL0FQ== + dependencies: + "@typescript-eslint/experimental-utils" "4.8.1" + "@typescript-eslint/scope-manager" "4.8.1" + debug "^4.1.1" + functional-red-black-tree "^1.0.1" + regexpp "^3.0.0" + semver "^7.3.2" + tsutils "^3.17.1" + "@typescript-eslint/experimental-utils@4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.0.1.tgz#7d9a3ab6821ad5274dad2186c1aa0d93afd696eb" @@ -1803,6 +1816,18 @@ eslint-scope "^5.0.0" eslint-utils "^2.0.0" +"@typescript-eslint/experimental-utils@4.8.1": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.8.1.tgz#27275c20fa4336df99ebcf6195f7d7aa7aa9f22d" + integrity sha512-WigyLn144R3+lGATXW4nNcDJ9JlTkG8YdBWHkDlN0lC3gUGtDi7Pe3h5GPvFKMcRz8KbZpm9FJV9NTW8CpRHpg== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/scope-manager" "4.8.1" + "@typescript-eslint/types" "4.8.1" + "@typescript-eslint/typescript-estree" "4.8.1" + eslint-scope "^5.0.0" + eslint-utils "^2.0.0" + "@typescript-eslint/parser@^4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.0.1.tgz#73772080db7a7a4534a35d719e006f503e664dc3" @@ -1813,6 +1838,16 @@ "@typescript-eslint/typescript-estree" "4.0.1" debug "^4.1.1" +"@typescript-eslint/parser@^4.8.1": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.8.1.tgz#4fe2fbdbb67485bafc4320b3ae91e34efe1219d1" + integrity sha512-QND8XSVetATHK9y2Ltc/XBl5Ro7Y62YuZKnPEwnNPB8E379fDsvzJ1dMJ46fg/VOmk0hXhatc+GXs5MaXuL5Uw== + dependencies: + "@typescript-eslint/scope-manager" "4.8.1" + "@typescript-eslint/types" "4.8.1" + "@typescript-eslint/typescript-estree" "4.8.1" + debug "^4.1.1" + "@typescript-eslint/scope-manager@4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.0.1.tgz#24d93c3000bdfcc5a157dc4d32b742405a8631b5" @@ -1821,11 +1856,24 @@ "@typescript-eslint/types" "4.0.1" "@typescript-eslint/visitor-keys" "4.0.1" +"@typescript-eslint/scope-manager@4.8.1": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.8.1.tgz#e343c475f8f1d15801b546cb17d7f309b768fdce" + integrity sha512-r0iUOc41KFFbZdPAdCS4K1mXivnSZqXS5D9oW+iykQsRlTbQRfuFRSW20xKDdYiaCoH+SkSLeIF484g3kWzwOQ== + dependencies: + "@typescript-eslint/types" "4.8.1" + "@typescript-eslint/visitor-keys" "4.8.1" + "@typescript-eslint/types@4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.0.1.tgz#1cf72582f764931f085cb8230ff215980fe467b2" integrity sha512-S+gD3fgbkZYW2rnbjugNMqibm9HpEjqZBZkTiI3PwbbNGWmAcxolWIUwZ0SKeG4Dy2ktpKKaI/6+HGYVH8Qrlg== +"@typescript-eslint/types@4.8.1": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.8.1.tgz#23829c73c5fc6f4fcd5346a7780b274f72fee222" + integrity sha512-ave2a18x2Y25q5K05K/U3JQIe2Av4+TNi/2YuzyaXLAsDx6UZkz1boZ7nR/N6Wwae2PpudTZmHFXqu7faXfHmA== + "@typescript-eslint/typescript-estree@4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.0.1.tgz#29a43c7060641ec51c902d9f50ac7c5866ec479f" @@ -1840,6 +1888,20 @@ semver "^7.3.2" tsutils "^3.17.1" +"@typescript-eslint/typescript-estree@4.8.1": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.8.1.tgz#7307e3f2c9e95df7daa8dc0a34b8c43b7ec0dd32" + integrity sha512-bJ6Fn/6tW2g7WIkCWh3QRlaSU7CdUUK52shx36/J7T5oTQzANvi6raoTsbwGM11+7eBbeem8hCCKbyvAc0X3sQ== + dependencies: + "@typescript-eslint/types" "4.8.1" + "@typescript-eslint/visitor-keys" "4.8.1" + debug "^4.1.1" + globby "^11.0.1" + is-glob "^4.0.1" + lodash "^4.17.15" + semver "^7.3.2" + tsutils "^3.17.1" + "@typescript-eslint/visitor-keys@4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.0.1.tgz#d4e8de62775f2a6db71c7e8539633680039fdd6c" @@ -1848,6 +1910,14 @@ "@typescript-eslint/types" "4.0.1" eslint-visitor-keys "^2.0.0" +"@typescript-eslint/visitor-keys@4.8.1": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.8.1.tgz#794f68ee292d1b2e3aa9690ebedfcb3a8c90e3c3" + integrity sha512-3nrwXFdEYALQh/zW8rFwP4QltqsanCDz4CwWMPiIZmwlk9GlvBeueEIbq05SEq4ganqM0g9nh02xXgv5XI3PeQ== + dependencies: + "@typescript-eslint/types" "4.8.1" + eslint-visitor-keys "^2.0.0" + "@webassemblyjs/ast@1.9.0": version "1.9.0" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964" @@ -10066,10 +10136,10 @@ react-color@^2.14.0: reactcss "^1.2.0" tinycolor2 "^1.4.1" -react-dom@17.0.0: +"react-dom@npm:@hot-loader/react-dom": version "17.0.0" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.0.tgz#f8266e4d9861584553ccbd186d596a1c7dd8dcb4" - integrity sha512-OGnFbxCjI2TMAZYMVxi4hqheJiN8rCEVVrL7XIGzCB6beNc4Am8M47HtkvxODZw9QgjmAPKpLba9FTu4fC1byA== + resolved "https://registry.yarnpkg.com/@hot-loader/react-dom/-/react-dom-17.0.0.tgz#1caa41d16006833717a8443d47e8677a9610dc7c" + integrity sha512-Po7ZIrs31ruikciz6bdUM2SNbz+I0ghIVFU+T5Gg9PBm05jn1lzKKysb2XGf4ZG/5og2nbqm4olUZw/lXEE3jg== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" @@ -10301,14 +10371,6 @@ react-useportal@^1.0.13: dependencies: use-ssr "^1.0.19" -react@17.0.0: - version "17.0.0" - resolved "https://registry.yarnpkg.com/react/-/react-17.0.0.tgz#ad96d5fa1a33bb9b06d0cc52672f7992d84aa662" - integrity sha512-rG9bqS3LMuetoSUKHN8G3fMNuQOePKDThK6+2yXFWtoeTDLVNh/QCaxT+Jr+rNf4lwNXpx+atdn3Aa0oi8/6eQ== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - react@^16.13.1, react@^16.3.0: version "16.13.1" resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e" @@ -10318,6 +10380,14 @@ react@^16.13.1, react@^16.3.0: object-assign "^4.1.1" prop-types "^15.6.2" +react@^17.0.0: + version "17.0.1" + resolved "https://registry.yarnpkg.com/react/-/react-17.0.1.tgz#6e0600416bd57574e3f86d92edba3d9008726127" + integrity sha512-lG9c9UuMHdcAexXtigOZLX8exLWkW0Ku29qPRU8uhF2R9BN96dLCt0psvzPLlHc5OWkgymP3qwTRgbnw5BKx3w== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + reactcss@^1.2.0: version "1.2.3" resolved "https://registry.yarnpkg.com/reactcss/-/reactcss-1.2.3.tgz#c00013875e557b1cf0dfd9a368a1c3dab3b548dd" @@ -12200,10 +12270,10 @@ typescript@^3.6.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa" integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw== -typescript@^4.0.2: - version "4.0.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2" - integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ== +typescript@^4.1.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.2.tgz#6369ef22516fe5e10304aae5a5c4862db55380e9" + integrity sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ== uglify-js@3.4.x: version "3.4.10"