@atlaspack/transformer-compiled 0.1.1-dev-swc44-3ef36b21e.0 → 0.2.1-canary.4115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  * allowing users to transition without any change in functionality.
11
11
  */
12
12
  const path_1 = require("path");
13
+ const assert_1 = __importDefault(require("assert"));
13
14
  const core_1 = require("@babel/core");
14
15
  const generator_1 = __importDefault(require("@babel/generator"));
15
16
  const utils_1 = require("@compiled/utils");
@@ -17,6 +18,14 @@ const plugin_1 = require("@atlaspack/plugin");
17
18
  const source_map_1 = __importDefault(require("@atlaspack/source-map"));
18
19
  const utils_2 = require("@atlaspack/utils");
19
20
  const utils_3 = require("./utils");
21
+ const babel_plugin_1 = __importDefault(require("@compiled/babel-plugin"));
22
+ const babel_plugin_strip_runtime_1 = __importDefault(require("@compiled/babel-plugin-strip-runtime"));
23
+ // @ts-expect-error no declaration file
24
+ // eslint-disable-next-line import/no-extraneous-dependencies
25
+ const plugin_syntax_jsx_1 = __importDefault(require("@babel/plugin-syntax-jsx"));
26
+ // @ts-expect-error no declaration file
27
+ // eslint-disable-next-line import/no-extraneous-dependencies
28
+ const plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
20
29
  const configFiles = [
21
30
  '.compiledcssrc',
22
31
  '.compiledcssrc.json',
@@ -28,7 +37,7 @@ const packageKey = '@atlaspack/transformer-compiled';
28
37
  * Atlaspack Compiled transformer.
29
38
  */
30
39
  exports.default = new plugin_1.Transformer({
31
- async loadConfig({ config, options }) {
40
+ async setup({ config, options }) {
32
41
  const conf = await config.getConfigFrom((0, path_1.join)(options.projectRoot, 'index'), configFiles, {
33
42
  packageKey,
34
43
  });
@@ -58,68 +67,72 @@ exports.default = new plugin_1.Transformer({
58
67
  }
59
68
  Object.assign(contents, conf.contents);
60
69
  }
61
- return contents;
62
- },
63
- canReuseAST() {
64
- // Compiled should run before any other JS transformer.
65
- return false;
70
+ let importSourceMatches = [
71
+ ...utils_1.DEFAULT_IMPORT_SOURCES,
72
+ ...(contents.importSources || []),
73
+ ];
74
+ return {
75
+ config: {
76
+ compiledConfig: contents,
77
+ mode: options.mode,
78
+ projectRoot: options.projectRoot,
79
+ },
80
+ conditions: {
81
+ codeMatch: importSourceMatches,
82
+ },
83
+ env: [
84
+ // TODO revisit this list, since we may have added variables in here that were actually enumarated rather than accessed directly
85
+ 'BABEL_ENV',
86
+ 'BABEL_SHOW_CONFIG_FOR',
87
+ 'BROWSERSLIST',
88
+ 'BROWSERSLIST_CONFIG',
89
+ 'BROWSERSLIST_DISABLE_CACHE',
90
+ 'BROWSERSLIST_ENV',
91
+ 'BROWSERSLIST_IGNORE_OLD_DATA',
92
+ 'BABEL_TYPES_8_BREAKING',
93
+ 'BROWSERSLIST_ROOT_PATH',
94
+ 'BROWSERSLIST_STATS',
95
+ 'AUTOPREFIXER',
96
+ 'AUTOPREFIXER_GRID',
97
+ 'TEST_PKG_VERSION',
98
+ 'FORCE_COLOR',
99
+ 'DEBUG',
100
+ 'NODE_DEBUG',
101
+ 'CI',
102
+ 'COLORTERM',
103
+ ],
104
+ };
66
105
  },
67
- async parse({ asset, config, options }) {
106
+ async transform({ asset, config }) {
107
+ if (config.compiledConfig.extract &&
108
+ config.compiledConfig.classHashPrefix) {
109
+ throw new Error('`@atlaspack/transformer-compiled` is mixing `extract: true` and `classHashPrefix` options, which will not supported and will result in bundle size bloat.');
110
+ }
68
111
  // Disable stylesheet extraction locally due to https://github.com/atlassian-labs/compiled/issues/1306
69
- const extract = config.extract && options.mode !== 'development';
112
+ const extract = config.compiledConfig.extract && config.mode !== 'development';
70
113
  if (!asset.isSource && !extract) {
71
114
  // Only parse source (pre-built code should already have been baked) or if stylesheet extraction is enabled
72
- return undefined;
115
+ return [asset];
73
116
  }
74
117
  const code = await asset.getCode();
75
118
  if (
76
119
  // If neither Compiled (default) nor any of the additional import sources are found in the code, we bail out.
77
- [...utils_1.DEFAULT_IMPORT_SOURCES, ...(config.importSources || [])].every((importSource) => !code.includes(importSource))) {
120
+ [
121
+ ...utils_1.DEFAULT_IMPORT_SOURCES,
122
+ ...(config.compiledConfig.importSources || []),
123
+ ].every((importSource) => !code.includes(importSource))) {
78
124
  // We only want to parse files that are actually using Compiled.
79
125
  // For everything else we bail out.
80
- return undefined;
126
+ return [asset];
81
127
  }
82
128
  if (code.includes('/* COMPILED_TRANSFORMED_ASSET */')) {
83
129
  // If we're dealing with a pre-transformed asset, we bail out to avoid performing the expensive parse operation.
84
130
  // We add this marker to the code to indicate that the asset has already been transformed.
85
- return undefined;
86
- }
87
- const program = await (0, core_1.parseAsync)(code, {
88
- filename: asset.filePath,
89
- babelrc: false,
90
- configFile: false,
91
- caller: { name: 'compiled' },
92
- rootMode: 'upward-optional',
93
- parserOpts: {
94
- // @ts-expect-error - Type mismatch between @babel/parser and @compiled/utils versions
95
- plugins: config.parserBabelPlugins ?? utils_1.DEFAULT_PARSER_BABEL_PLUGINS,
96
- },
97
- plugins: config.transformerBabelPlugins ?? undefined,
98
- });
99
- if (program) {
100
- return {
101
- type: 'babel',
102
- version: '7.0.0',
103
- program,
104
- };
105
- }
106
- return undefined;
107
- },
108
- async transform({ asset, config, options }) {
109
- if (config.extract && config.classHashPrefix) {
110
- throw new Error('`@atlaspack/transformer-compiled` is mixing `extract: true` and `classHashPrefix` options, which will not supported and will result in bundle size bloat.');
111
- }
112
- const ast = await asset.getAST();
113
- if (!(ast?.type === 'babel' && ast.program)) {
114
- // We will only receive ASTs for assets we're interested in.
115
- // Since this is undefined (or in node modules) we aren't interested in it.
116
131
  return [asset];
117
132
  }
118
133
  // Disable stylesheet extraction locally due to https://github.com/atlassian-labs/compiled/issues/1306
119
- const extract = config.extract && options.mode !== 'development';
120
134
  const includedFiles = [];
121
- const code = asset.isASTDirty() ? undefined : await asset.getCode();
122
- const result = await (0, core_1.transformFromAstAsync)(ast.program, code, {
135
+ const result = await (0, core_1.transformAsync)(code, {
123
136
  code: false,
124
137
  ast: true,
125
138
  filename: asset.filePath,
@@ -127,29 +140,27 @@ exports.default = new plugin_1.Transformer({
127
140
  configFile: false,
128
141
  sourceMaps: !!asset.env.sourceMap,
129
142
  compact: false,
130
- parserOpts: {
131
- // @ts-expect-error - Type mismatch between @babel/parser and @compiled/utils versions
132
- plugins: config.parserBabelPlugins ?? utils_1.DEFAULT_PARSER_BABEL_PLUGINS,
133
- },
134
143
  plugins: [
135
- ...(config.transformerBabelPlugins ?? []),
144
+ plugin_syntax_jsx_1.default,
145
+ [plugin_syntax_typescript_1.default, { isTSX: true }],
136
146
  asset.isSource && [
137
- '@compiled/babel-plugin',
147
+ babel_plugin_1.default,
138
148
  {
139
149
  ...config,
140
- classNameCompressionMap: config.extract && config.classNameCompressionMap,
150
+ classNameCompressionMap: config.compiledConfig.extract &&
151
+ config.compiledConfig.classNameCompressionMap,
141
152
  onIncludedFiles: (files) => includedFiles.push(...files),
142
- resolver: config.resolver
143
- ? config.resolver
144
- : (0, utils_3.createDefaultResolver)(config),
153
+ resolver: config.compiledConfig.resolver
154
+ ? config.compiledConfig.resolver
155
+ : (0, utils_3.createDefaultResolver)(config.compiledConfig),
145
156
  cache: false,
146
157
  },
147
158
  ],
148
159
  extract && [
149
- '@compiled/babel-plugin-strip-runtime',
160
+ babel_plugin_strip_runtime_1.default,
150
161
  {
151
162
  compiledRequireExclude: true,
152
- extractStylesToDirectory: config.extractStylesToDirectory,
163
+ extractStylesToDirectory: config.compiledConfig.extractStylesToDirectory,
153
164
  },
154
165
  ],
155
166
  ].filter(utils_1.toBoolean),
@@ -171,24 +182,16 @@ exports.default = new plugin_1.Transformer({
171
182
  ...(metadata.styleRules ?? []),
172
183
  ];
173
184
  }
174
- if (result?.ast) {
175
- asset.setAST({
176
- type: 'babel',
177
- version: '7.0.0',
178
- program: result.ast,
179
- });
180
- }
181
- return [asset];
182
- },
183
- async generate({ asset, ast, options }) {
184
185
  const originalSourceMap = await asset.getMap();
185
- const sourceFileName = (0, utils_2.relativeUrl)(options.projectRoot, asset.filePath);
186
- const { code, rawMappings } = (0, generator_1.default)(ast.program, {
186
+ const sourceFileName = (0, utils_2.relativeUrl)(config.projectRoot, asset.filePath);
187
+ (0, assert_1.default)(result?.ast, 'Babel transform returned no AST');
188
+ const { code: generatedCode, rawMappings } = (0, generator_1.default)(result.ast.program, {
187
189
  sourceFileName,
188
190
  sourceMaps: !!asset.env.sourceMap,
189
191
  comments: true,
190
192
  });
191
- const map = new source_map_1.default(options.projectRoot);
193
+ asset.setCode(generatedCode);
194
+ const map = new source_map_1.default(config.projectRoot);
192
195
  if (rawMappings) {
193
196
  map.addIndexedMappings(rawMappings);
194
197
  }
@@ -203,9 +206,6 @@ exports.default = new plugin_1.Transformer({
203
206
  }
204
207
  }
205
208
  }
206
- return {
207
- content: code,
208
- map,
209
- };
209
+ return [asset];
210
210
  },
211
211
  });
@@ -1,7 +1,13 @@
1
1
  import { Transformer } from '@atlaspack/plugin';
2
2
  import type { CompiledTransformerOpts } from './types';
3
+ import { BuildMode } from '@atlaspack/types';
4
+ interface Config {
5
+ compiledConfig: CompiledTransformerOpts;
6
+ mode: BuildMode;
7
+ projectRoot: string;
8
+ }
3
9
  /**
4
10
  * Atlaspack Compiled transformer.
5
11
  */
6
- declare const _default: Transformer<CompiledTransformerOpts>;
12
+ declare const _default: Transformer<Config>;
7
13
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-compiled",
3
- "version": "0.1.1-dev-swc44-3ef36b21e.0",
3
+ "version": "0.2.1-canary.4115+c294ec464",
4
4
  "description": "Atlaspack transformer for Compiled CSS-in-JS (insourced from @compiled/parcel-transformer)",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -21,22 +21,24 @@
21
21
  "src"
22
22
  ],
23
23
  "dependencies": {
24
- "@atlaspack/plugin": "2.14.46-dev-swc44-3ef36b21e.0",
25
- "@atlaspack/source-map": "3.2.1-dev-swc44-3ef36b21e.0",
26
- "@atlaspack/utils": "3.2.7-dev-swc44-3ef36b21e.0",
24
+ "@atlaspack/plugin": "2.14.5-canary.336+c294ec464",
25
+ "@atlaspack/source-map": "3.2.2-canary.4115+c294ec464",
26
+ "@atlaspack/utils": "2.14.5-canary.336+c294ec464",
27
27
  "@babel/core": "^7.22.11",
28
28
  "@babel/generator": "^7.22.10",
29
+ "@babel/plugin-syntax-jsx": "^7.27.1",
30
+ "@babel/plugin-syntax-typescript": "^7.27.1",
29
31
  "@compiled/babel-plugin": "^0.38.0",
30
32
  "@compiled/babel-plugin-strip-runtime": "^0.38.0",
31
33
  "@compiled/utils": "^0.13.1",
32
34
  "enhanced-resolve": "^5.18.1"
33
35
  },
34
36
  "devDependencies": {
35
- "@atlaspack/types": "2.15.36-dev-swc44-3ef36b21e.0"
37
+ "@atlaspack/types": "2.14.5-canary.336+c294ec464"
36
38
  },
37
39
  "type": "commonjs",
38
40
  "scripts": {
39
41
  "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
40
42
  },
41
- "gitHead": "3ef36b21e388934416729737de94a47adf5e6ca4"
43
+ "gitHead": "c294ec464d8c195f9ad0d34ccf1a6ec1dbf7e4b4"
42
44
  }
@@ -5,25 +5,31 @@
5
5
  * allowing users to transition without any change in functionality.
6
6
  */
7
7
  import {join} from 'path';
8
+ import assert from 'assert';
8
9
 
9
- import {parseAsync, transformFromAstAsync} from '@babel/core';
10
+ import {transformAsync} from '@babel/core';
10
11
  import generate from '@babel/generator';
11
12
  import type {PluginOptions as BabelPluginOptions} from '@compiled/babel-plugin';
12
13
  import type {
13
14
  PluginOptions as BabelStripRuntimePluginOptions,
14
15
  BabelFileMetadata,
15
16
  } from '@compiled/babel-plugin-strip-runtime';
16
- import {
17
- DEFAULT_IMPORT_SOURCES,
18
- DEFAULT_PARSER_BABEL_PLUGINS,
19
- toBoolean,
20
- } from '@compiled/utils';
17
+ import {DEFAULT_IMPORT_SOURCES, toBoolean} from '@compiled/utils';
21
18
  import {Transformer} from '@atlaspack/plugin';
22
19
  import SourceMap from '@atlaspack/source-map';
23
20
  import {relativeUrl} from '@atlaspack/utils';
24
21
 
25
22
  import type {CompiledTransformerOpts} from './types';
26
23
  import {createDefaultResolver} from './utils';
24
+ import {BuildMode} from '@atlaspack/types';
25
+ import CompiledBabelPlugin from '@compiled/babel-plugin';
26
+ import CompiledBabelPluginStripRuntime from '@compiled/babel-plugin-strip-runtime';
27
+ // @ts-expect-error no declaration file
28
+ // eslint-disable-next-line import/no-extraneous-dependencies
29
+ import BabelPluginSyntaxJsx from '@babel/plugin-syntax-jsx';
30
+ // @ts-expect-error no declaration file
31
+ // eslint-disable-next-line import/no-extraneous-dependencies
32
+ import BabelPluginSyntaxTypescript from '@babel/plugin-syntax-typescript';
27
33
 
28
34
  const configFiles = [
29
35
  '.compiledcssrc',
@@ -34,11 +40,17 @@ const configFiles = [
34
40
 
35
41
  const packageKey = '@atlaspack/transformer-compiled';
36
42
 
43
+ interface Config {
44
+ compiledConfig: CompiledTransformerOpts;
45
+ mode: BuildMode;
46
+ projectRoot: string;
47
+ }
48
+
37
49
  /**
38
50
  * Atlaspack Compiled transformer.
39
51
  */
40
- export default new Transformer<CompiledTransformerOpts>({
41
- async loadConfig({config, options}) {
52
+ export default new Transformer<Config>({
53
+ async setup({config, options}) {
42
54
  const conf = await config.getConfigFrom<CompiledTransformerOpts>(
43
55
  join(options.projectRoot, 'index'),
44
56
  configFiles,
@@ -84,84 +96,84 @@ export default new Transformer<CompiledTransformerOpts>({
84
96
  Object.assign(contents, conf.contents);
85
97
  }
86
98
 
87
- return contents;
88
- },
99
+ let importSourceMatches = [
100
+ ...DEFAULT_IMPORT_SOURCES,
101
+ ...(contents.importSources || []),
102
+ ];
89
103
 
90
- canReuseAST() {
91
- // Compiled should run before any other JS transformer.
92
- return false;
104
+ return {
105
+ config: {
106
+ compiledConfig: contents,
107
+ mode: options.mode,
108
+ projectRoot: options.projectRoot,
109
+ },
110
+ conditions: {
111
+ codeMatch: importSourceMatches,
112
+ },
113
+ env: [
114
+ // TODO revisit this list, since we may have added variables in here that were actually enumarated rather than accessed directly
115
+ 'BABEL_ENV',
116
+ 'BABEL_SHOW_CONFIG_FOR',
117
+ 'BROWSERSLIST',
118
+ 'BROWSERSLIST_CONFIG',
119
+ 'BROWSERSLIST_DISABLE_CACHE',
120
+ 'BROWSERSLIST_ENV',
121
+ 'BROWSERSLIST_IGNORE_OLD_DATA',
122
+ 'BABEL_TYPES_8_BREAKING',
123
+ 'BROWSERSLIST_ROOT_PATH',
124
+ 'BROWSERSLIST_STATS',
125
+ 'AUTOPREFIXER',
126
+ 'AUTOPREFIXER_GRID',
127
+ 'TEST_PKG_VERSION',
128
+ 'FORCE_COLOR',
129
+ 'DEBUG',
130
+ 'NODE_DEBUG',
131
+ 'CI',
132
+ 'COLORTERM',
133
+ ],
134
+ };
93
135
  },
94
136
 
95
- async parse({asset, config, options}) {
137
+ async transform({asset, config}) {
138
+ if (
139
+ config.compiledConfig.extract &&
140
+ config.compiledConfig.classHashPrefix
141
+ ) {
142
+ throw new Error(
143
+ '`@atlaspack/transformer-compiled` is mixing `extract: true` and `classHashPrefix` options, which will not supported and will result in bundle size bloat.',
144
+ );
145
+ }
146
+
96
147
  // Disable stylesheet extraction locally due to https://github.com/atlassian-labs/compiled/issues/1306
97
- const extract = config.extract && options.mode !== 'development';
148
+ const extract =
149
+ config.compiledConfig.extract && config.mode !== 'development';
98
150
  if (!asset.isSource && !extract) {
99
151
  // Only parse source (pre-built code should already have been baked) or if stylesheet extraction is enabled
100
- return undefined;
152
+ return [asset];
101
153
  }
102
154
 
103
155
  const code = await asset.getCode();
104
156
  if (
105
157
  // If neither Compiled (default) nor any of the additional import sources are found in the code, we bail out.
106
- [...DEFAULT_IMPORT_SOURCES, ...(config.importSources || [])].every(
107
- (importSource) => !code.includes(importSource),
108
- )
158
+ [
159
+ ...DEFAULT_IMPORT_SOURCES,
160
+ ...(config.compiledConfig.importSources || []),
161
+ ].every((importSource) => !code.includes(importSource))
109
162
  ) {
110
163
  // We only want to parse files that are actually using Compiled.
111
164
  // For everything else we bail out.
112
- return undefined;
165
+ return [asset];
113
166
  }
114
167
  if (code.includes('/* COMPILED_TRANSFORMED_ASSET */')) {
115
168
  // If we're dealing with a pre-transformed asset, we bail out to avoid performing the expensive parse operation.
116
169
  // We add this marker to the code to indicate that the asset has already been transformed.
117
- return undefined;
118
- }
119
-
120
- const program = await parseAsync(code, {
121
- filename: asset.filePath,
122
- babelrc: false,
123
- configFile: false,
124
- caller: {name: 'compiled'},
125
- rootMode: 'upward-optional',
126
- parserOpts: {
127
- // @ts-expect-error - Type mismatch between @babel/parser and @compiled/utils versions
128
- plugins: config.parserBabelPlugins ?? DEFAULT_PARSER_BABEL_PLUGINS,
129
- },
130
- plugins: config.transformerBabelPlugins ?? undefined,
131
- });
132
-
133
- if (program) {
134
- return {
135
- type: 'babel',
136
- version: '7.0.0',
137
- program,
138
- };
139
- }
140
-
141
- return undefined;
142
- },
143
-
144
- async transform({asset, config, options}) {
145
- if (config.extract && config.classHashPrefix) {
146
- throw new Error(
147
- '`@atlaspack/transformer-compiled` is mixing `extract: true` and `classHashPrefix` options, which will not supported and will result in bundle size bloat.',
148
- );
149
- }
150
-
151
- const ast = await asset.getAST();
152
-
153
- if (!(ast?.type === 'babel' && ast.program)) {
154
- // We will only receive ASTs for assets we're interested in.
155
- // Since this is undefined (or in node modules) we aren't interested in it.
156
170
  return [asset];
157
171
  }
158
172
 
159
173
  // Disable stylesheet extraction locally due to https://github.com/atlassian-labs/compiled/issues/1306
160
- const extract = config.extract && options.mode !== 'development';
161
174
  const includedFiles: string[] = [];
162
- const code = asset.isASTDirty() ? undefined : await asset.getCode();
163
175
 
164
- const result = await transformFromAstAsync(ast.program, code, {
176
+ const result = await transformAsync(code, {
165
177
  code: false,
166
178
  ast: true,
167
179
  filename: asset.filePath,
@@ -169,30 +181,29 @@ export default new Transformer<CompiledTransformerOpts>({
169
181
  configFile: false,
170
182
  sourceMaps: !!asset.env.sourceMap,
171
183
  compact: false,
172
- parserOpts: {
173
- // @ts-expect-error - Type mismatch between @babel/parser and @compiled/utils versions
174
- plugins: config.parserBabelPlugins ?? DEFAULT_PARSER_BABEL_PLUGINS,
175
- },
176
184
  plugins: [
177
- ...(config.transformerBabelPlugins ?? []),
185
+ BabelPluginSyntaxJsx,
186
+ [BabelPluginSyntaxTypescript, {isTSX: true}],
178
187
  asset.isSource && [
179
- '@compiled/babel-plugin',
188
+ CompiledBabelPlugin,
180
189
  {
181
190
  ...config,
182
191
  classNameCompressionMap:
183
- config.extract && config.classNameCompressionMap,
192
+ config.compiledConfig.extract &&
193
+ config.compiledConfig.classNameCompressionMap,
184
194
  onIncludedFiles: (files: string[]) => includedFiles.push(...files),
185
- resolver: config.resolver
186
- ? config.resolver
187
- : createDefaultResolver(config),
195
+ resolver: config.compiledConfig.resolver
196
+ ? config.compiledConfig.resolver
197
+ : createDefaultResolver(config.compiledConfig),
188
198
  cache: false,
189
199
  } as BabelPluginOptions,
190
200
  ],
191
201
  extract && [
192
- '@compiled/babel-plugin-strip-runtime',
202
+ CompiledBabelPluginStripRuntime,
193
203
  {
194
204
  compiledRequireExclude: true,
195
- extractStylesToDirectory: config.extractStylesToDirectory,
205
+ extractStylesToDirectory:
206
+ config.compiledConfig.extractStylesToDirectory,
196
207
  } as BabelStripRuntimePluginOptions,
197
208
  ],
198
209
  ].filter(toBoolean),
@@ -217,25 +228,15 @@ export default new Transformer<CompiledTransformerOpts>({
217
228
  ];
218
229
  }
219
230
 
220
- if (result?.ast) {
221
- asset.setAST({
222
- type: 'babel',
223
- version: '7.0.0',
224
- program: result.ast,
225
- });
226
- }
227
-
228
- return [asset];
229
- },
230
-
231
- async generate({asset, ast, options}) {
232
231
  const originalSourceMap = await asset.getMap();
233
232
  const sourceFileName: string = relativeUrl(
234
- options.projectRoot,
233
+ config.projectRoot,
235
234
  asset.filePath,
236
235
  );
237
236
 
238
- const {code, rawMappings} = generate(ast.program, {
237
+ assert(result?.ast, 'Babel transform returned no AST');
238
+
239
+ const {code: generatedCode, rawMappings} = generate(result.ast.program, {
239
240
  sourceFileName,
240
241
  sourceMaps: !!asset.env.sourceMap,
241
242
  comments: true,
@@ -249,7 +250,9 @@ export default new Transformer<CompiledTransformerOpts>({
249
250
  }>;
250
251
  };
251
252
 
252
- const map = new SourceMap(options.projectRoot);
253
+ asset.setCode(generatedCode);
254
+
255
+ const map = new SourceMap(config.projectRoot);
253
256
  if (rawMappings) {
254
257
  map.addIndexedMappings(rawMappings);
255
258
  }
@@ -266,9 +269,6 @@ export default new Transformer<CompiledTransformerOpts>({
266
269
  }
267
270
  }
268
271
 
269
- return {
270
- content: code,
271
- map,
272
- };
272
+ return [asset];
273
273
  },
274
274
  });