-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for legacy decorators through tsconfig/jsconfig (#31376)
- Loading branch information
1 parent
ae1cee5
commit e0531e3
Showing
9 changed files
with
128 additions
and
42 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
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { join } from 'path' | ||
import webdriver from 'next-webdriver' | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { check } from 'next-test-utils' | ||
|
||
describe('Legacy decorators SWC option', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
'jsconfig.json': new FileRef( | ||
join(__dirname, 'legacy-decorators/jsconfig.json') | ||
), | ||
pages: new FileRef(join(__dirname, 'legacy-decorators/pages')), | ||
}, | ||
dependencies: { | ||
mobx: '6.3.7', | ||
'mobx-react': '7.2.1', | ||
}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should compile with legacy decorators enabled', async () => { | ||
let browser | ||
try { | ||
browser = await webdriver(next.appPort, '/') | ||
const text = await browser.elementByCss('#count').text() | ||
expect(text).toBe('Current number: 0') | ||
await browser.elementByCss('#increase').click() | ||
await check( | ||
() => browser.elementByCss('#count').text(), | ||
/Current number: 1/ | ||
) | ||
} finally { | ||
if (browser) { | ||
await browser.close() | ||
} | ||
} | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"experimentalDecorators": true | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react' | ||
import { makeAutoObservable } from 'mobx' | ||
import { observer } from 'mobx-react' | ||
|
||
class Counter { | ||
count = 0 | ||
|
||
constructor() { | ||
makeAutoObservable(this) | ||
} | ||
|
||
increase() { | ||
this.count += 1 | ||
} | ||
} | ||
|
||
const myCounter = new Counter() | ||
|
||
@observer | ||
class CounterView extends React.Component { | ||
render() { | ||
return ( | ||
<> | ||
<span id="count">Current number: {this.props.counter.count}</span> | ||
<button id="increase" onClick={() => this.props.counter.increase()}> | ||
Increase | ||
</button> | ||
</> | ||
) | ||
} | ||
} | ||
|
||
export default function Home() { | ||
return <CounterView counter={myCounter} /> | ||
} |