Skip to content

Commit

Permalink
chore: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsjtu committed Apr 16, 2024
1 parent a2b8f7a commit 85f8a18
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('parse', () => {
];
configs.forEach(({ name, config }) => {
it(`parse() with double </template> with config=${name}`, () => {
const result = parse('<template></template></template>', '', config);
const result = parse('<template></template></template>', config);
const expectWarning = config.apiVersion === 58; // null/undefined/unspecified is treated as latest
expect(result.warnings.length).toBe(1);
expect(result.warnings[0].level).toBe(
Expand Down
6 changes: 3 additions & 3 deletions packages/@lwc/template-compiler/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ export interface Config {
*/
apiVersion?: number;
}
type OptionalConfigValues = 'customRendererConfig' | 'instrumentation' | 'namespace' | 'name';
type RequiredConfigOptions = Required<Omit<Config, OptionalConfigValues>>;
type OptionalConfigOptions = Partial<Pick<Config, OptionalConfigValues>>;
type OptionalConfigNames = 'customRendererConfig' | 'instrumentation' | 'namespace' | 'name';
type RequiredConfigOptions = Required<Omit<Config, OptionalConfigNames>>;
type OptionalConfigOptions = Partial<Pick<Config, OptionalConfigNames>>;
export type NormalizedConfig = RequiredConfigOptions & OptionalConfigOptions;

const AVAILABLE_OPTION_NAMES = new Set([
Expand Down
12 changes: 5 additions & 7 deletions packages/@lwc/template-compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@ export { Config } from './config';
/**
* Parses HTML markup into an AST
* @param source HTML markup to parse
* @param filename HTML filename
* @param config HTML template compilation config
* @returns Object containing the AST
*/
export function parse(
source: string,
filename: string = '',
config: Config = {}
): TemplateParseResult {
export function parse(source: string, config: Config = {}): TemplateParseResult {
const options = normalizeConfig(config);
const state = new State(options, filename);
// The file name is never used in this function, defaulting it to an empty string.
const state = new State(options, '');
return parseTemplate(source, state);
}

Expand All @@ -56,6 +52,8 @@ export default function compile(
config: Config
): TemplateCompileResult {
const options = normalizeConfig(config);
// Note the file name is required to generate implicit css imports and style tokens.
// It is not part of the config because all values in the config are optional by convention.
const state = new State(options, filename);

let code = '';
Expand Down

0 comments on commit 85f8a18

Please sign in to comment.