diff --git a/compiler/apps/playground/__tests__/e2e/page.spec.ts b/compiler/apps/playground/__tests__/e2e/page.spec.ts index 94abe40eeb864..8ad9f122aab34 100644 --- a/compiler/apps/playground/__tests__/e2e/page.spec.ts +++ b/compiler/apps/playground/__tests__/e2e/page.spec.ts @@ -314,6 +314,36 @@ test('disableMemoizationForDebugging flag works as expected', async ({ expect(output).toMatchSnapshot('disableMemoizationForDebugging-output.txt'); }); +test('error is displayed when source has syntax error', async ({page}) => { + const syntaxErrorSource = `function TestComponent(props) { + const oops = props. + return ( + <>{oops} + ); +}`; + const store: Store = { + source: syntaxErrorSource, + config: defaultConfig, + showInternals: false, + }; + const hash = encodeStore(store); + await page.goto(`/#${hash}`); + await page.waitForFunction(isMonacoLoaded); + await expandConfigs(page); + await page.screenshot({ + fullPage: true, + path: 'test-results/08-source-syntax-error.png', + }); + + const text = + (await page.locator('.monaco-editor-output').allInnerTexts()) ?? []; + const output = text.join(''); + + expect(output.replace(/\s+/g, ' ')).toContain( + 'Expected identifier to be defined before being used', + ); +}); + TEST_CASE_INPUTS.forEach((t, idx) => test(`playground compiles: ${t.name}`, async ({page}) => { const store: Store = { diff --git a/compiler/apps/playground/lib/compilation.ts b/compiler/apps/playground/lib/compilation.ts index 10bf0164c0e77..f668c05dde2a6 100644 --- a/compiler/apps/playground/lib/compilation.ts +++ b/compiler/apps/playground/lib/compilation.ts @@ -297,7 +297,7 @@ export function compile( if (!error.hasErrors() && otherErrors.length !== 0) { otherErrors.forEach(e => error.details.push(e)); } - if (error.hasErrors()) { + if (error.hasErrors() || !transformOutput) { return [{kind: 'err', results, error}, language, baseOpts]; } return [