Repository: pyscript/pyscript
File: pyscriptjs/src/components/pyscript.ts (TypeScript)

Code before:
import { htmlDecode, ensureUniqueId, showWarning } from '../utils';
import type { Runtime } from '../runtime';
import { getLogger } from '../logger';
import { pyExec } from '../pyexec';
import { _createAlertBanner } from '../exceptions';
import { robustFetch } from '../fetch';

const logger = getLogger('py-script');

export function make_PyScript(runtime: Runtime) {
    class PyScript extends HTMLElement {
        srcCode: string

        async connectedCallback() {
            if (this.hasAttribute('output')) {
                const deprecationMessage = (
                    "The 'output' attribute is deprecated and ignored. You should use " +
                    "'display()' to output the content to a specific element. " +
                    'For example display(myElement, target="divID").'
                )
                showWarning(deprecationMessage)
            }
            ensureUniqueId(this);
            this.srcCode = this.innerHTML;
            const pySrc = await this.getPySrc();
            this.innerHTML = '';
            pyExec(runtime, pySrc, this);
        }

        async getPySrc(): Promise<string> {
            if (this.hasAttribute('src')) {
                const url = this.getAttribute('src');
                try {
                    const response = await robustFetch(url);
                    return await response.text();
                } catch(e) {
                    _createAlertBanner(e.message);

Review comment (suggestion):
This could become

```suggestion
        // Save innerHTML information in srcCode so we can access it
        // once connectedCallback cleans innerHTML
        srcCode: string = this.innerHTML
```

So we don't need to do the assignment on line 24, I've added the comment there because it's not clean why we are doing this 😄 

Code after:
import { htmlDecode, ensureUniqueId, showWarning } from '../utils';
import type { Runtime } from '../runtime';
import { getLogger } from '../logger';
import { pyExec } from '../pyexec';
import { _createAlertBanner } from '../exceptions';
import { robustFetch } from '../fetch';

const logger = getLogger('py-script');

export function make_PyScript(runtime: Runtime) {
    class PyScript extends HTMLElement {
        srcCode: string

        async connectedCallback() {
            if (this.hasAttribute('output')) {
                const deprecationMessage = (
                    "The 'output' attribute is deprecated and ignored. You should use " +
                    "'display()' to output the content to a specific element. " +
                    'For example display(myElement, target="divID").'
                )
                showWarning(deprecationMessage)
            }
            ensureUniqueId(this);
            // Save innerHTML information in srcCode so we can access it later
            // once we clean innerHTML (which is required since we don't want
            // source code to be rendered on the screen)
            this.srcCode = this.innerHTML;
            const pySrc = await this.getPySrc();
            this.innerHTML = '';
            pyExec(runtime, pySrc, this);
        }

        async getPySrc(): Promise<string> {
            if (this.hasAttribute('src')) {
                const url = this.getAttribute('src');
                try {
                    const response = await robustFetch(url);