Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate EuiTable and a bunch of other stuff to TS #2212

Merged
merged 23 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d5a3d28
WIP - migrating all kinds of things to TS
pugnascotia Aug 2, 2019
0a0dfc4
Merge remote-tracking branch 'upstream/master' into ts-migrations
pugnascotia Aug 6, 2019
db0d14b
More WIP
pugnascotia Aug 6, 2019
b2a7992
Various type fixes
pugnascotia Aug 8, 2019
6b372aa
Fix tests
pugnascotia Aug 8, 2019
fe67279
Merge remote-tracking branch 'upstream/master' into ts-migrations
pugnascotia Aug 8, 2019
b063347
Change quirky syntax
pugnascotia Aug 8, 2019
048f939
Update changelog
pugnascotia Aug 8, 2019
f0b3366
Fix ts->proptype script by 1. not duplicating PropTypes import 2. sup…
chandlerprall Aug 9, 2019
9ae0ecb
Merge pull request #2 from chandlerprall/pull/2212
pugnascotia Aug 12, 2019
bca5b9b
Merge remote-tracking branch 'upstream/master' into migrate-all-the-t…
pugnascotia Aug 12, 2019
238eb8a
Type fixes
pugnascotia Aug 12, 2019
2c8e39b
Remove old type defs and fix some types
pugnascotia Aug 13, 2019
7352120
Fix some more old type def cruft
pugnascotia Aug 13, 2019
e3970ec
more exports
thompsongl Aug 13, 2019
1bf567f
remove SPACING type
thompsongl Aug 13, 2019
99527de
Merge pull request #3 from thompsongl/migrate-all-the-ts-things
pugnascotia Aug 14, 2019
b1f656c
Merge branch 'master' into migrate-all-the-ts-things
pugnascotia Aug 14, 2019
5edf49d
Merge branch 'master' into migrate-all-the-ts-things
pugnascotia Aug 16, 2019
4ddcec1
Merge branch 'master' into migrate-all-the-ts-things
pugnascotia Aug 19, 2019
c5d17dc
Merge branch 'master' into migrate-all-the-ts-things
thompsongl Aug 19, 2019
be109a9
Merge remote-tracking branch 'upstream/master' into migrate-all-the-t…
pugnascotia Aug 23, 2019
19793a7
Merge remote-tracking branch 'origin/migrate-all-the-ts-things' into …
pugnascotia Aug 23, 2019
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
- Fixed `EuiSwitch` semantics to align with aria roles ([#2193](https://github.com/elastic/eui/pull/2193))
- Removed Firefox's focus ring to match other browsers ([#2193](https://github.com/elastic/eui/pull/2193))
- Added missing `onChange` TS defs for EuiRange ([#2211](https://github.com/elastic/eui/pull/2211))
- Fixed `EuiStat` invalid DOM nesting due to a `<p>` tag nested within another `<p>` tag ([#2229](https://github.com/elastic/eui/pull/2229))
- Fixed `EuiBadge` text cursor to default pointer ([#2234](https://github.com/elastic/eui/pull/2234))
- Converted table, popover, buttons, pagination, outside click detector, focus trap, context menu, and panel to TypeScript ([#2212](https://github.com/elastic/eui/pull/2212))

## [`13.3.0`](https://github.com/elastic/eui/tree/v13.3.0)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@types/react-is": "~16.3.0",
"@types/react-virtualized": "^9.18.6",
"@types/resize-observer-browser": "^0.1.1",
"@types/tabbable": "^3.1.0",
"@types/uuid": "^3.4.4",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
Expand Down
28 changes: 21 additions & 7 deletions scripts/babel/proptypes-from-ts-props/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const path = require('path');
const babelTemplate = require('babel-template');
const babelCore = require('@babel/core');

const importedDefinitionsCache = new Map();

// react-docgen does not understand typescript annotations
function stripTypeScript(filename, ast) {
return babelCore.transform(
Expand Down Expand Up @@ -809,6 +811,16 @@ const typeDefinitionExtractors = {
return [];
}

if (importedDefinitionsCache.has(resolvedPath)) {
return importedDefinitionsCache.get(resolvedPath);
}

// to support circular dependencies, create & pre-cache the array of imported dependencies
// this array is directly mutated after parsing the subsequent files, supporting
// the circular nature as values settle into the correct locations
const importedDefinitions = [];
importedDefinitionsCache.set(resolvedPath, importedDefinitions);

// load & parse the imported file
const ast = parse(fs.readFileSync(resolvedPath).toString());

Expand Down Expand Up @@ -840,18 +852,15 @@ const typeDefinitionExtractors = {
);

// for each importedTypeName, fully resolve the type information
const importedDefinitions = definitions.reduce(
(importedDefinitions, { name, definition }) => {
definitions.forEach(
({ name, definition }) => {
if (importedTypeNames.includes(name)) {
// this type declaration is imported by the parent script
const propTypes = getPropTypesForNode(definition, true, state);
propTypes.isAlreadyResolved = true; // when getPropTypesForNode is called on this node later, tell it to skip processing
importedDefinitions.push({ name, definition: propTypes });
}

return importedDefinitions;
},
[]
}
);

// reset typeDefinitions and continue processing the original file
Expand Down Expand Up @@ -1026,7 +1035,7 @@ function processComponentDeclaration(typeDefinition, path, state) {

// import PropTypes library if it isn't already
const proptypesBinding = getVariableBinding(path, 'PropTypes');
if (proptypesBinding == null) {
if (proptypesBinding == null && state.get('hasInjectedPropTypes') !== true) {
let targetNode;
// find the first statement in the program and import PropTypes there
targetNode = path;
Expand All @@ -1043,6 +1052,7 @@ function processComponentDeclaration(typeDefinition, path, state) {
types.stringLiteral('prop-types')
)
);
state.set('hasInjectedPropTypes', true);
}
}

Expand Down Expand Up @@ -1268,3 +1278,7 @@ module.exports = function propTypesFromTypeScript({ types }) {
},
};
};

module.exports.clearImportCache = function clearImportCache() {
importedDefinitionsCache.clear();
}
3 changes: 3 additions & 0 deletions scripts/babel/proptypes-from-ts-props/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const babelOptions = {
],
filename: 'somefile.tsx',
};
const babelPlugin = require('./index');

beforeEach(() => babelPlugin.clearImportCache());

describe('proptypes-from-ts-props', () => {

Expand Down
54 changes: 27 additions & 27 deletions src-docs/src/i18ntokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -661,95 +661,95 @@
"highlighting": "string",
"loc": {
"start": {
"line": 37,
"line": 61,
"column": 6
},
"end": {
"line": 41,
"line": 65,
"column": 57
}
},
"filepath": "src/components/pagination/pagination.js"
"filepath": "src/components/pagination/pagination.tsx"
},
{
"token": "euiPagination.previousPage",
"defString": "Previous page",
"highlighting": "string",
"loc": {
"start": {
"line": 57,
"line": 81,
"column": 4
},
"end": {
"line": 57,
"line": 81,
"column": 72
}
},
"filepath": "src/components/pagination/pagination.js"
"filepath": "src/components/pagination/pagination.tsx"
},
{
"token": "euiPagination.pageOfTotal",
"defString": "Page {page} of {total}",
"highlighting": "string",
"loc": {
"start": {
"line": 75,
"line": 99,
"column": 6
},
"end": {
"line": 79,
"line": 103,
"column": 53
}
},
"filepath": "src/components/pagination/pagination.js"
"filepath": "src/components/pagination/pagination.tsx"
},
{
"token": "euiPagination.jumpToLastPage",
"defString": "Jump to the last page, number {pageCount}",
"highlighting": "string",
"loc": {
"start": {
"line": 120,
"line": 144,
"column": 6
},
"end": {
"line": 124,
"line": 148,
"column": 31
}
},
"filepath": "src/components/pagination/pagination.js"
"filepath": "src/components/pagination/pagination.tsx"
},
{
"token": "euiPagination.nextPage",
"defString": "Next page",
"highlighting": "string",
"loc": {
"start": {
"line": 138,
"line": 162,
"column": 4
},
"end": {
"line": 138,
"line": 162,
"column": 64
}
},
"filepath": "src/components/pagination/pagination.js"
"filepath": "src/components/pagination/pagination.tsx"
},
{
"token": "euiPopover.screenReaderAnnouncement",
"defString": "You are in a popup. To exit this popup, hit escape.",
"highlighting": "string",
"loc": {
"start": {
"line": 442,
"line": 587,
"column": 14
},
"end": {
"line": 445,
"line": 590,
"column": 16
}
},
"filepath": "src/components/popover/popover.js"
"filepath": "src/components/popover/popover.tsx"
},
{
"token": "euiSelectable.loadingOptions",
Expand Down Expand Up @@ -917,47 +917,47 @@
"highlighting": "string",
"loc": {
"start": {
"line": 50,
"line": 49,
"column": 8
},
"end": {
"line": 50,
"line": 49,
"column": 72
}
},
"filepath": "src/components/table/mobile/table_sort_mobile.js"
"filepath": "src/components/table/mobile/table_sort_mobile.tsx"
},
{
"token": "euiTablePagination.rowsPerPage",
"defString": "Rows per page",
"highlighting": "string",
"loc": {
"start": {
"line": 50,
"line": 62,
"column": 8
},
"end": {
"line": 53,
"line": 65,
"column": 10
}
},
"filepath": "src/components/table/table_pagination/table_pagination.js"
"filepath": "src/components/table/table_pagination/table_pagination.tsx"
},
{
"token": "euiTablePagination.rowsPerPageOption",
"defString": "{rowsPerPage} rows",
"highlighting": "string",
"loc": {
"start": {
"line": 66,
"line": 78,
"column": 8
},
"end": {
"line": 70,
"line": 82,
"column": 10
}
},
"filepath": "src/components/table/table_pagination/table_pagination.js"
"filepath": "src/components/table/table_pagination/table_pagination.tsx"
},
{
"token": "euiToast.dismissToast",
Expand Down
Loading