-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: fix babel typescript compilation of abstract classes
- Loading branch information
Showing
13 changed files
with
68 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1 @@ | ||
const defaultConfig = require('../../support/babel/base.babel'); | ||
|
||
module.exports = { | ||
...defaultConfig, | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
targets: { | ||
node: '8', | ||
}, | ||
}, | ||
], | ||
'@babel/preset-typescript', | ||
'@babel/preset-react', | ||
], | ||
plugins: [ | ||
// 'babel-plugin-styled-components', | ||
...defaultConfig.plugins, | ||
], | ||
env: { | ||
test: { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: '8', | ||
}, | ||
}, | ||
], | ||
'@babel/preset-typescript', | ||
'@babel/preset-react', | ||
], | ||
}, | ||
}, | ||
}; | ||
module.exports = require('../../support/babel/base.babel'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
import { Doc, Paragraph, Text } from '..'; | ||
|
||
// While these tests seem simple there is a reason for them. | ||
// | ||
// While using abstract classes in TypeScript if the code is compiled with TS the compiled properties are not | ||
// added to the class definition. This means I can declare an abstract property on a base class and letter extend that class | ||
// defining the class with a getter for that property without any issue. | ||
// For some reason when using babel and the `@babel/preset-typescript` this was not the case. | ||
// Getters defined in parent classes were being ignored as the value was being set to void. | ||
// The solution has been to remove this preset and replace it with the plugin `@babel/plugin-transform-typescript` | ||
// placed as the first plugin in the list. | ||
// | ||
// If the abstract class code is run through the Babel TS plugin first then it is handled properly.. | ||
// These tests are here as a flag, in case someone does changes the babel compile pipeline in a way that breaks things. | ||
|
||
describe('nodes', () => { | ||
test('doc', () => { | ||
const doc = new Doc(); | ||
expect(doc.name).toBe('doc'); | ||
expect(doc.pluginKey).toContainEntry(['key', 'doc$']); | ||
}); | ||
|
||
test('paragraph', () => { | ||
const paragraph = new Paragraph(); | ||
expect(paragraph.name).toBe('paragraph'); | ||
expect(paragraph.pluginKey).toContainEntry(['key', 'paragraph$']); | ||
}); | ||
|
||
test('text', () => { | ||
const text = new Text(); | ||
expect(text.name).toBe('text'); | ||
expect(text.pluginKey).toContainEntry(['key', 'text$']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ module.exports = { | |
}, | ||
}, | ||
], | ||
'@babel/preset-typescript', | ||
], | ||
plugins: [...defaultConfig.plugins], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ module.exports = { | |
}, | ||
}, | ||
], | ||
'@babel/preset-typescript', | ||
], | ||
plugins: [...defaultConfig.plugins], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters